diff --git a/arrays-basics.js b/arrays-basics.js index 0de468d..a6801ac 100644 --- a/arrays-basics.js +++ b/arrays-basics.js @@ -2,31 +2,41 @@ Task 8 (logArray): Create a function logArray that receives an array as a parameter and logs each item in the array. **************************************************************/ -function logArray(arr) {} - +// 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"]); /************************************************************** 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) { +// return console.log(arr.filter((value,index)=> value %2===0)) +// } +// logEvenNumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); /************************************************************** Task 11 (logArrayBackwards): Create a function logArrayBackwards that receives an array as a parameter and logs each item in the array in reverse order. **************************************************************/ -function logArrayBackwards(arr) {} +// function logArrayBackwards(arr) { +// const rev=arr.reverse() +// console.log(rev); +// } // logArrayBackwards(["one", "two", "three", "four"]); @@ -34,14 +44,22 @@ function logArrayBackwards(arr) {} Task 12 (logLastItem): Create a function logLastItem that receives an array as a parameter and logs the last item in the array. **************************************************************/ -function logLastItem(arr) {} - +// function logLastItem(arr) { +// let last=arr.length-1 +// console.log(arr[last]); +// } // logLastItem(["a", "b", "c", "d"]); /************************************************************** Task 13 (logArrayInChunks): Create a function logArrayInChunks that receives an array and a chunk size as parameters and logs the items in the array in chunks of the specified size. **************************************************************/ -function logArrayInChunks(arr, chunkSize) {} +function logArrayInChunks(arr, chunkSize) { + for (let i=0;i accumulator + currentValue +// +// ); +// } // console.log(sumArray([4, 3, 2, 5, -10])); /************************************************************** @@ -15,13 +18,15 @@ function sumArray(numbers) { Hint: Use the .find() and .startsWith() methods **************************************************************/ -function findFirstStringStartingWithLetter(letter, strings) { - //TODO: Add your code here -} +// function findFirstStringStartingWithLetter(letter, strings) { +// //TODO: Add your code here + +// return strings.find((str)=>str.toLowerCase().startsWith(letter)) +// } // console.log( // findFirstStringStartingWithLetter("h", ["Memory", "Hello", "Happy"]) // ); - + /************************************************************** Task 3: Create a function isPresentIncluded that receives an array of presents as a parameter and uses the includes method to check @@ -29,9 +34,12 @@ function findFirstStringStartingWithLetter(letter, strings) { Hint: Use the .map() and .includes() methods **************************************************************/ -function isPresentIncluded(presentName, presents) { - //TODO: Add your code here -} +// function isPresentIncluded(presentName, presents) { +// // TODO: Add your code here +// return presents.map((value,index)=> +// value.toLowerCase().includes(presentName) +// ) +// } // console.log( // isPresentIncluded("puzzle", [ // "Sparkling Surprise", @@ -49,9 +57,10 @@ function isPresentIncluded(presentName, presents) { Hint: Use the .sort() method **************************************************************/ -function sortStudentsAlphabetically(students) { +// function sortStudentsAlphabetically(students) { //TODO: Add your code here -} +// return students.sort() +// } // console.log( // sortStudentsAlphabetically([ // "Eve", @@ -77,9 +86,17 @@ function sortStudentsAlphabetically(students) { Hint: Use the .forEach() and .push() methods **************************************************************/ -function separateOddEven(numbers) { - //TODO: Add your code here -} +// function separateOddEven(numbers) { +// //TODO: Add your code here +// let odds=[]; +// let evens=[]; +// numbers.forEach((num) => { +// if(num %2===0) { +// evens.push(num) +// } else {odds.push(num)} +// }); +// return {evens,odds} +// } // console.log(separateOddEven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); /************************************************************** @@ -99,9 +116,9 @@ function separateOddEven(numbers) { Hint: Use the .filter and .startsWith method **************************************************************/ -function removeItem(code, items) { - //TODO: Add your code here -} +// function removeItem(code, items) { +// // // TODO: Add your code here +// return items.filter((value,index)=>value.code !=code )} // console.log( // removeItem("#153", [ // { code: "#153", name: "Ball" }, @@ -158,14 +175,21 @@ Task 7: **************************************************************/ function updateGrades(curve, students) { //TODO: Add your code here + + students.map((value,index)=>{ + if (value.type==="nerd"){ + return value.grade-=curve + } else{return value.grade+=curve} + }) + return students } -// 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..1b7f759 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,6 @@ Arrays -