diff --git a/arrays-basics.js b/arrays-basics.js index 0de468d..98da7d9 100644 --- a/arrays-basics.js +++ b/arrays-basics.js @@ -2,7 +2,11 @@ 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]); @@ -10,7 +14,11 @@ function logArray(arr) {} 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"]); @@ -18,30 +26,40 @@ function logArrayWithIndex(arr) {} 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 arr.filter((items, index) => { +// return items % 2 === 0; +// }); +// } +// console.log(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) {} - -// logArrayBackwards(["one", "two", "three", "four"]); +// function logArrayBackwards(arr) { +// return arr.reverse(); +// } +// console.log(logArrayBackwards(["one", "two", "three", "four"])); /************************************************************** 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) {} - -// logLastItem(["a", "b", "c", "d"]); +// function logLastItem(arr) { +// return arr[arr.length - 1]; +// } +// console.log(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 < arr.length; i = i + chunkSize) { +// const checks = arr.slice(i, i + chunkSize); +// console.log(checks); +// } +// } // logArrayInChunks([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); diff --git a/arrays-intermediate.js b/arrays-intermediate.js index 18b8fb0..dba837e 100644 --- a/arrays-intermediate.js +++ b/arrays-intermediate.js @@ -3,11 +3,11 @@ Create a function sumArray that receives an array of numbers as a parameter and returns the sum of all the numbers in the array. Hint: Use the .reduce() method **************************************************************/ -function sumArray(numbers) { - //TODO: Add your code here -} +// function sumArray(numbers) { +// //TODO: Add your code here +// return numbers.reduce((items, value)=> items+value ) +// } // console.log(sumArray([4, 3, 2, 5, -10])); - /************************************************************** Task 2: Create a function findFirstStringStartingWithA that receives an array of strings as a parameter @@ -17,6 +17,7 @@ function sumArray(numbers) { **************************************************************/ function findFirstStringStartingWithLetter(letter, strings) { //TODO: Add your code here + return strings.find((str) => str.toLowerCase().startswith(letter)); } // console.log( // findFirstStringStartingWithLetter("h", ["Memory", "Hello", "Happy"]) @@ -29,9 +30,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) { +// return presents.map((items, index) => +// items.toLowerCase().includes(presentName) +// ); +// //TODO: Add your code here +// } // console.log( // isPresentIncluded("puzzle", [ // "Sparkling Surprise", @@ -46,12 +50,14 @@ function isPresentIncluded(presentName, presents) { Task 4: Create a function sortStudentsAlphabetically that receives an array of students name as a parameter and uses the sort method to sort the strings in alphabetical order. + Hint: Use the .sort() method **************************************************************/ -function sortStudentsAlphabetically(students) { - //TODO: Add your code here -} +// function sortStudentsAlphabetically(students) { +// return students.sort(); +// //TODO: Add your code here +// } // console.log( // sortStudentsAlphabetically([ // "Eve", @@ -77,9 +83,21 @@ function sortStudentsAlphabetically(students) { Hint: Use the .forEach() and .push() methods **************************************************************/ -function separateOddEven(numbers) { - //TODO: Add your code here -} +// function separateOddEven(numbers) { +// const odds = []; +// const even = []; +// numbers.forEach((items) => { +// if (items % 2 === 0) { +// odds.push(items); +// } else { +// even.push(items); +// } + +// }); +// return{even,odds} +// } +// //TODO: Add your code here + // console.log(separateOddEven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); /************************************************************** @@ -99,9 +117,13 @@ function separateOddEven(numbers) { Hint: Use the .filter and .startsWith method **************************************************************/ -function removeItem(code, items) { - //TODO: Add your code here -} +// function removeItem(code, items) { +// return items.filter((value,index)=> +// value.code != code +// ) +// } +// //TODO: Add your code here + // console.log( // removeItem("#153", [ // { code: "#153", name: "Ball" }, @@ -156,9 +178,17 @@ Task 7: Hint: Use the .map method and separator operator **************************************************************/ -function updateGrades(curve, students) { - //TODO: Add your code here -} +// function updateGrades(curve, students) { +// students.map((items, index) => { +// if (items.type === "regular") { +// return items.grade += curve +// } else { +// return items.grade -= curve +// } +// }); +// return students; +// } +// //TODO: Add your code here // console.log( // updateGrades(10, [ // { firstName: "Jaber", lastName: "jabarbar", grade: 10, type: "regular" }, diff --git a/index.html b/index.html index d971aeb..7e1a9dc 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,8 @@ Arrays - + \ No newline at end of file diff --git a/reviewers.js b/reviewers.js index eda2973..ead2b02 100644 --- a/reviewers.js +++ b/reviewers.js @@ -1,12 +1,14 @@ const reviewers = require("./reviewers.json"); +import reviewers from "./reviewers.json" assert { type: "json" }; console.log("🚀 ~ file: reviewers.js:2 ~ reviewers:", reviewers); /*********************************************************************** - This function receives a reviewer object and should return the name of the reviewer. ***********************************************************************/ -function getReviewerName(reviewer) { - //TODO: ADD YOUR CODE HERE -} +// function getReviewerName(reviewer) { +//TODO: ADD YOUR CODE HERE +// console.log(reviewer.reviewerName); +// } // console.log(getReviewerName(reviewers[0])); /*********************************************************************** @@ -14,6 +16,7 @@ function getReviewerName(reviewer) { ************************************************************************/ function numberOfReviews(reviewer) { //TODO: ADD YOUR CODE HERE + return reviewer.books.length; } // console.log(numberOfReviews(reviewers[0])); @@ -25,6 +28,9 @@ function numberOfReviews(reviewer) { ***********************************************************************/ function reviewerHasReview(reviewTitle, reviewer) { //TODO: ADD YOUR CODE HERE + reviewer.books.some((items) => { + return items.title === reviewTitle; + }); } // console.log(reviewerHasReview("Becoming", reviewers[0])); @@ -35,6 +41,7 @@ function reviewerHasReview(reviewTitle, reviewer) { ****************************************************************/ function getReviewerByName(reviewerName, reviewers) { //TODO: ADD YOUR CODE HERE + reviewers.find((items) => items.reviewerName === reviewerName); } // console.log(getReviewerByName("Michelle Obama", reviewers)); @@ -45,6 +52,11 @@ function getReviewerByName(reviewerName, reviewers) { ****************************************************************/ function getReviewerByReviewTitle(reviewTitle, reviewers) { //TODO: ADD YOUR CODE HERE + return reviewers.find((items) => { + items.some((value) => { + return value.books === reviewTitle; + }); + }); } // console.log(getReviewerByReviewTitle("The Overstory", reviewers)); @@ -56,4 +68,15 @@ function getReviewerByReviewTitle(reviewTitle, reviewers) { function searchReviewers(query, reviewers) { //TODO: ADD YOUR CODE HERE } +return reviewers.map((items) => { + items.reviewerName = items.reviewerName.toWloerCase(); +}); +return reviewers.map((items) => { + items.description = items.description.toWloerCase(); +}); +return reviewers.fiter((items) => { + if (items.reviewerName.includes(query) && items.description.includes(query)) { + return items; + } +}); // console.log(searchReviewers("o", reviewers));