diff --git a/arrays-basics.js b/arrays-basics.js index 0de468d..ce9062d 100644 --- a/arrays-basics.js +++ b/arrays-basics.js @@ -2,46 +2,64 @@ Task 8 (logArray): Create a function logArray that receives an array as a parameter and logs each item in the array. **************************************************************/ -function logArray(arr) {} - -// logArray([1, 2, 3, 4, 5]); +function logArray(arr) { +arr.forEach((value,index)=> console.log (value)); +} +logArray([1, 2, 3, 4, 5]); /************************************************************** Task 9 (logArrayWithIndex): Create a function logArrayWithIndex that receives an array as a parameter and logs each item in the array along with its index. **************************************************************/ -function logArrayWithIndex(arr) {} +function logArrayWithIndex(arr) { + arr.forEach((value,index)=>{console.log(value,index)}) +} -// logArrayWithIndex(["apple", "banana", "orange"]); +logArrayWithIndex(["apple", "banana", "orange"]); /************************************************************** Task 10 (logEvenNumbers): Create a function logEvenNumbers that receives an array of numbers as a parameter and logs only the even numbers in the array. **************************************************************/ -function logEvenNumbers(arr) {} - -// logEvenNumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); +function logEvenNumbers(arr) { + for(let i=0;i{ +// return accumulator+currentValue; +// }) +// return sum +// } // console.log(sumArray([4, 3, 2, 5, -10])); /************************************************************** @@ -15,11 +18,13 @@ function sumArray(numbers) { Hint: Use the .find() and .startsWith() methods **************************************************************/ -function findFirstStringStartingWithLetter(letter, strings) { - //TODO: Add your code here -} +// function findFirstStringStartingWithLetter(letter, strings) { +// var result = strings.find((value,index) => { +// return value.startsWith(letter);}) +// return result +// } // console.log( -// findFirstStringStartingWithLetter("h", ["Memory", "Hello", "Happy"]) +// findFirstStringStartingWithLetter("H", ["Memory", "Hello", "Happy"]) // ); /************************************************************** @@ -29,11 +34,11 @@ function findFirstStringStartingWithLetter(letter, strings) { Hint: Use the .map() and .includes() methods **************************************************************/ -function isPresentIncluded(presentName, presents) { - //TODO: Add your code here -} +// function isPresentIncluded(presentName, presents) { +// return presents.includes(presentName) +// } // console.log( -// isPresentIncluded("puzzle", [ +// isPresentIncluded("blabla", [ // "Sparkling Surprise", // "Enchanted Elegance", // "Whimsical Wonder", @@ -49,9 +54,10 @@ function isPresentIncluded(presentName, presents) { Hint: Use the .sort() method **************************************************************/ -function sortStudentsAlphabetically(students) { - //TODO: Add your code here -} +// function sortStudentsAlphabetically(students) { +// const sortedlist =students.sort() +// return sortedlist +// } // console.log( // sortStudentsAlphabetically([ // "Eve", @@ -77,9 +83,20 @@ function sortStudentsAlphabetically(students) { Hint: Use the .forEach() and .push() methods **************************************************************/ -function separateOddEven(numbers) { - //TODO: Add your code here -} +// function separateOddEven(numbers) { +// let odds =[] +// let evens =[] +// numbers.forEach((value,index) => { +// if (value%2 ==0){ +// evens.push(value) +// }else { +// odds.push(value) +// } + +// }); +// return {odds , evens} + +// } // console.log(separateOddEven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); /************************************************************** @@ -99,9 +116,12 @@ function separateOddEven(numbers) { Hint: Use the .filter and .startsWith method **************************************************************/ -function removeItem(code, items) { - //TODO: Add your code here -} +// function removeItem(code, items) { +// const itemsAfterRemove = items.filter((value,index)=>{ +// return value.code != code; +// }) +// console.log(itemsAfterRemove) +// } // console.log( // removeItem("#153", [ // { code: "#153", name: "Ball" }, @@ -157,15 +177,23 @@ Task 7: Hint: Use the .map method and separator operator **************************************************************/ function updateGrades(curve, students) { - //TODO: Add your code here + + const updatedGrades = students.map((std)=>{ + if (std.type !=="nerd"){ + return { ...std, grade:std.grade+curve}; + } + else{return std} + } + ) + return updatedGrades } -// console.log( -// updateGrades(10, [ -// { firstName: "Jaber", lastName: "jabarbar", grade: 10, type: "regular" }, -// { firstName: "Hamza", lastName: "Alhamazi", grade: 12, type: "regular" }, -// { firstName: "Jasem", lastName: "Jamasmas", grade: 15, type: "nerd" }, -// { firstName: "Kadhim", lastName: "Khadhmia", grade: 5, type: "regular" }, -// { firstName: "Um Abbas", lastName: "IDK", grade: 20, type: "nerd" }, -// { firstName: "Johny", lastName: "Micle", grade: 10, type: "regular" }, -// ]) -// ); +console.log( + updateGrades(10, [ + { firstName: "Jaber", lastName: "jabarbar", grade: 10, type: "regular" }, + { firstName: "Hamza", lastName: "Alhamazi", grade: 12, type: "regular" }, + { firstName: "Jasem", lastName: "Jamasmas", grade: 15, type: "nerd" }, + { firstName: "Kadhim", lastName: "Khadhmia", grade: 5, type: "regular" }, + { firstName: "Um Abbas", lastName: "IDK", grade: 20, type: "nerd" }, + { firstName: "Johny", lastName: "Micle", grade: 10, type: "regular" }, + ]) +); diff --git a/index.html b/index.html index d971aeb..668d707 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,7 @@ Arrays -