Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise solutions #386

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions solution/day-01/level3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

//Q1
const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] ;
const sorted = ages.sort(( a,b)=> a-b);
let maxAge = sorted[sorted.length-1];
let minAge = sorted[0];

// Median age

const mid = Math.floor(ages.length/2);

if(mid%2===0){
const median = (ages[mid-1]+ages[mid])/2;
return median;
}
else{
const medianNun = arr[mid];
return medianNun;
}

// average age
let sum = 0;

for(let i=0;i<ages.length;i++){
sum+=ages[i];
}
const average = sum/(ages.length);


//Q1.1
countries.slice(0,10);

//Q2
const middleEl = Math.floor(countries.length/2)-1;
const medianEl = (countries[middleEl-1]+countries[middleEl])/2;

countries.splice(middleEl,2);








125 changes: 125 additions & 0 deletions solutions/day-01/level1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Exercise level-1 solutions

// Q.1
const arr = [];

// Q.2
const myArr = [1,2,3,4,5,6,7,8,9]

//Q 3
console.log(myArr.length); // 9

//Q 4
(myArr[0]);// 1
const mid = Math.floor(myArr.length/2);//
(myArr[mid]);
(myArr[myArr.length -1]);//9

//Q5
const mixedDataTypes = [1,"firo",true,2.5,"welcome",false,10];
console.log(mixedDataTypes.length);//7

//Q6
const companies = ["Facebook","Google","Microsoft","Apple","IBM","Oracle","Amazon"];

//Q7
console.log(companies);

//Q8
console.log(companies.length);

//Q9
console.log(companies[0]);
const midd = Math.floor(companies.length / 2);
console.log(companies[midd]);
console.log(companies[companies.length-1]);

//Q10
console.log(companies[0]);
console.log(companies[1]);
console.log(companies[2]);
console.log(companies[3]);
console.log(companies[4]);
console.log(companies[5]);
console.log(companies[6]);
console.log(companies[7]);

//Q11
console.log(companies[0].toUpperCase());
console.log(companies[1].toUpperCase());
console.log(companies[2].toUpperCase());
console.log(companies[3].toUpperCase());
console.log(companies[4].toUpperCase());
console.log(companies[5].toUpperCase());
console.log(companies[6].toUpperCase());
console.log(companies[7].toUpperCase());

//Q12
console.log(companies.join(',')+ " are big companies");

//Q13
if(companies.includes("Twitter")){
return "Twitter";
}
else{
return "company not found";
}

//Q14

const filteredCompanies = [];
for(let i=0;i<companies.length;i++){
const company = companies[i];
let count=0;
for(let j=0;j<company.length;j++){
if(company[j].toLowerCase()==='o'){
count+=1;
}
}
if(count>1){
filteredCompanies.push(company);
}
}
console.log(filteredCompanies);

//Q15
companies.sort((a,b)=> a -b);

//Q16
companies.reverse();

//Q17
companies.slice(0,3);

//Q18
companies.slice(-3);

//Q19
const middle = Math.floor(companies.length / 2);
let slicedArray ;
if(companies.length %2 === 0){
slicedArray = companies.slice(middle -1,middle+1)
}
else{
slicedArray = companies[middle];
}
console.log(slicedArray);

//Q20

companies.shift();

//Q21
const middleIndex = Math.floor(companies.length/2);

const removedElement = companies.splice(middleIndex,1);

//Q22

companies.pop();

//Q23
companies.splice(0,companies.length);



15 changes: 15 additions & 0 deletions solutions/day-01/level2/countries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya',
]

export default countries;
54 changes: 54 additions & 0 deletions solutions/day-01/level2/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// level 2 solutions
//Q1
import countries from "./countries";
import webTechs from "./web_techs";


//Q2
let text =
'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'

const words = sentence.replace(/[^\w\s]/g,'');
const wordsArray = words.split(" ");
const wordCount = wordsArray.length;
console.log(wordsArray)
console.log(wordCount);

//Q3
const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'];
shoppingCart.unshift("Meat");
if(shoppingCart.indexOf("Sugar")===-1){
shoppingCart.push("Sugar");
}

const honeyIndex = 3;
shoppingCart.splice(3,1);
shoppingCart[2]="Green Tea";

//Q4


if(countries.indexOf("Ethiopia")===-1){
countries.push("Ethiopia");
}
else{
console.log("ETHIOPIA");
}

//Q5

if(webTechs.indexOf("Sass")===-1){
webTechs.push("Sass");
console.log(webTechs);
}
else{
console.log("Sass is CSS preprocess");
}

//Q6
const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux']
const backEnd = ['Node', 'Express', 'MongoDB']
const fullStack = frontEnd.concat(backEnd);
console.log(fullStack);


24 changes: 24 additions & 0 deletions solutions/day-01/level2/solutions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//Q2
let text =
'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'

const words = sentence.replace(/[^\w\s]/g,'');
const wordsArray = words.split(" ");
const wordCount = wordsArray.length;
console.log(wordsArray)
console.log(wordCount);

//Q3
const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'];
shoppingCart.unshift("Meat");
if(shoppingCart.indexOf("Sugar")===-1){
shoppingCart.push("Sugar");
}

const honeyIndex = 3;
shoppingCart.splice(3,1);
shoppingCart[2]="Green Tea";

//Q4


10 changes: 10 additions & 0 deletions solutions/day-01/level2/web_techs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB',
]
export default webTechs;
1 change: 1 addition & 0 deletions solutions/day-02/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
41 changes: 41 additions & 0 deletions solutions/day-02/exercises.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
1 .what is React?
--------------
1. what is React?

--React is a JavaScript library for building a reusable user interface(UI). It was initially released on May 29, 2013.
React makes creating UI components very easy

2. what is library?

--- library is a collection of pre-written code and resources that provide specific functionality and can be reused in different projects. A library typically consists of a set of functions, classes, or modules that encapsulate specific tasks or features, making it easier for developers to incorporate that functionality into their own applications without having to write everything from scratch.

3.what is component?

---In React, a component is a reusable and self-contained building block for building user interfaces. Components are the fundamental units of a React application, and they can be thought of as custom HTML elements that encapsulate their own functionality, state, and rendering logic.

4. what is a singlepage application?

---A Single-Page Application (SPA) is a web application that loads and operates within a single HTML page. Instead of navigating to different pages by requesting new HTML documents from the server, a single-page application dynamically updates the existing page by manipulating the Document Object Model (DOM) in response to user interactions.

5.what is the latest version of React?
---- 17.02

6.What is DOM?

DOM stands for Document Object Model. It is a programming interface for web documents, representing the structure and content of an HTML or XML document as a tree-like structure. The DOM represents the web page in a way that allows programming languages, like JavaScript, to interact with and manipulate the content, structure, and style of the document.

7.What is React Virtual DOM?

React Virtual DOM (Virtual Document Object Model) is a concept and technique used by React to optimize the rendering performance of web applications. It is a lightweight and efficient representation of the actual DOM that React uses to track and manage changes to the user interface.

8.What does a web application or a website(composed of) have?

A web application or website is composed of various components,that work together to deliver the desired functionality and user experience. Here are some key components commonly found in a web application or website:

User Interface (UI): The user interface encompasses the visual and interactive elements of the application or website that users interact with. It includes components such as menus, buttons, forms, images, and other visual elements that facilitate user interaction.

HTML/CSS: HTML (Hypertext Markup Language) and CSS (Cascading Style Sheets) are the foundational technologies used to structure and style web pages. HTML defines the structure and content of the page, while CSS is used to define the visual presentation and layout of the elements.

JavaScript: JavaScript is a powerful scripting language that runs in the browser and enables dynamic interactivity and functionality on web pages. It is commonly used to handle user interactions, perform client-side validation, manipulate the DOM, make asynchronous requests to servers (AJAX), and implement various features and behaviors.

Backend: The backend of a web application consists of server-side technologies and infrastructure responsible for processing requests, handling business logic, and interacting with