diff --git a/solutions/DAY-01/ARRAYS/countries.js b/solutions/DAY-01/ARRAYS/countries.js index 6d35241..381a2c6 100644 --- a/solutions/DAY-01/ARRAYS/countries.js +++ b/solutions/DAY-01/ARRAYS/countries.js @@ -12,4 +12,5 @@ const countries = [ 'Kenya', ] + module.exports = countries \ No newline at end of file diff --git a/solutions/DAY-01/ARRAYS/level3.js b/solutions/DAY-01/ARRAYS/level3.js new file mode 100644 index 0000000..d0e85d5 --- /dev/null +++ b/solutions/DAY-01/ARRAYS/level3.js @@ -0,0 +1,41 @@ +const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]; + +// Sort the array and find the min and max age +ages.sort((a, b) => a - b); +const minAge = ages[0]; +const maxAge = ages[ages.length - 1]; + +// Find the median age (one middle item or two middle items divided by two) +const middleIndex = Math.floor(ages.length / 2); +const medianAge = ages.length % 2 === 0 ? (ages[middleIndex - 1] + ages[middleIndex]) / 2 : ages[middleIndex]; + +// Find the average age (all items divided by number of items) +const sumOfAges = ages.reduce((total, age) => total + age, 0); +const averageAge = sumOfAges / ages.length; + +// Find the range of the ages (max minus min) +const ageRange = maxAge - minAge; + +// Compare the value of (min - average) and (max - average), use abs() method +const diffMinAverage = Math.abs(minAge - averageAge); +const diffMaxAverage = Math.abs(maxAge - averageAge); + +console.log(`Sorted array of ages: ${ages}`); +console.log(`Minimum age: ${minAge}`); +console.log(`Maximum age: ${maxAge}`); +console.log(`Median age: ${medianAge}`); +console.log(`Average age: ${averageAge}`); +console.log(`Age range: ${ageRange}`); +console.log(`Absolute difference between minimum age and average age: ${diffMinAverage}`); +console.log(`Absolute difference between maximum age and average age: ${diffMaxAverage}`); + + + +const firstTenCountries = countries.slice(0, 10); +const midd = Math.floor(countries.length / 2); +const middleCountry = countries[midd]; + + +const halfLength = Math.ceil(countries.length / 2); +const firstHalf = countries.slice(0, halfLength); +const secondHalf = countries.slice(halfLength); diff --git a/solutions/DAY-01/ARRAYS/main.js b/solutions/DAY-01/ARRAYS/main.js index 9b49a9e..4ad0d16 100644 --- a/solutions/DAY-01/ARRAYS/main.js +++ b/solutions/DAY-01/ARRAYS/main.js @@ -1,6 +1,45 @@ -import * as countries from './countries'; -import * as webtech from './web_techs'; +const countries = require('./countries') +const webTechs = require('./web_techs.js') -console.log(webTechs) -console.log(countries) +let text = 'I love teaching and empowering people I teach HTML CSS JS React Python' + +const text_arr = text.split(" ") +console.log(text_arr + "\n" + text_arr.length) + +let shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'] +shoppingCart.unshift("Meat") +shoppingCart.pop() +shoppingCart[3] = "Green Tea" +shoppingCart.push("Sugar") + + +let num = countries.indexOf("Ethiopia") + +if (num = -1) { + countries.push("ethiopia") + console.log(countries) +} +else{ + console.log("ETHIOPIA") +} + + +let tech_num = webTechs.indexOf("Sass") + + +if (tech_num = -1){ + webTechs.push("Sass") + console.log(webTechs) +} +else{ + console.log("Sass is a css process") +} + + +const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux'] +const backEnd = ['Node', 'Express', 'MongoDB'] + +const fullStack = frontEnd.concat(backEnd) + +console.log(fullStack) \ No newline at end of file diff --git a/solutions/DAY-01/ARRAYS/web_techs.js b/solutions/DAY-01/ARRAYS/web_techs.js index a057439..53ac483 100644 --- a/solutions/DAY-01/ARRAYS/web_techs.js +++ b/solutions/DAY-01/ARRAYS/web_techs.js @@ -6,4 +6,6 @@ const webTechs = [ 'Redux', 'Node', 'MongoDB', - ] \ No newline at end of file + ] + + module.exports = webTechs \ No newline at end of file diff --git a/solutions/DAY-01/CONDITIONALS/level1 copy.html b/solutions/DAY-01/CONDITIONALS/level1 copy.html new file mode 100644 index 0000000..1be52ef --- /dev/null +++ b/solutions/DAY-01/CONDITIONALS/level1 copy.html @@ -0,0 +1,30 @@ + + +
+ + +