Skip to content
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
48 changes: 42 additions & 6 deletions arrays-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,82 @@
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) {}

// function logEvenNumbers(arr) {
// arr.forEach((value, index) => {
// if (value % 2 == 0) {
// console.log(value);
// }
// });
// }

// 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 rvers =arr.reverse();
// console.log(rvers)
// }


// 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) {}

// function logLastItem(arr) {
// arr.map((value, index) => {
// console.log(value);

// if (index == arr.length - 1) {
// console.log("---------------------");
// console.log("last item is :", value);
// }
// });
// }

// 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 count = arr.slice(i, i +chunkSize);
// console.log(count);
// }
// }

// logArrayInChunks([1, 2, 3, 4, 5, 6, 7, 8, 9], 3);
67 changes: 46 additions & 21 deletions arrays-intermediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
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) {
// return numbers.reduce((acc ,curr)=> acc + curr )
// };
// console.log(sumArray([4, 3, 2, 5, -10]));

/**************************************************************
Expand All @@ -15,9 +15,11 @@ 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((value , index) => value.toLowerCase().startsWith(letter))
// }
// console.log(
// findFirstStringStartingWithLetter("h", ["Memory", "Hello", "Happy"])
// );
Expand All @@ -29,9 +31,10 @@ 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)=> value.toLowerCase().includes(presentName))
// }
// console.log(
// isPresentIncluded("puzzle", [
// "Sparkling Surprise",
Expand All @@ -49,9 +52,10 @@ function isPresentIncluded(presentName, presents) {

Hint: Use the .sort() method
**************************************************************/
function sortStudentsAlphabetically(students) {
//TODO: Add your code here
}
// function sortStudentsAlphabetically(students) {
// //TODO: Add your code here
// return students.sort()
// }
// console.log(
// sortStudentsAlphabetically([
// "Eve",
Expand All @@ -77,9 +81,20 @@ 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 even =[];
// let odd =[];
// numbers.forEach((value ,index) => {
// if (value % 2 === 0){
// even.push(value)
// }else{
// odd.push(value)
// }

// });
// return {even,odd}
// }
// console.log(separateOddEven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));

/**************************************************************
Expand All @@ -99,9 +114,10 @@ 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)=> value.code != code );
// }
// console.log(
// removeItem("#153", [
// { code: "#153", name: "Ball" },
Expand Down Expand Up @@ -156,9 +172,18 @@ Task 7:

Hint: Use the .map method and separator operator
**************************************************************/
function updateGrades(curve, students) {
//TODO: Add your code here
}
// function updateGrades(curve, students) {
// //TODO: Add your code here
// students.map((value,index)=>{
// if(value.type === "nerd"){
// value.grade -= curve
// }else{
// value.grade += curve
// }

// });
// return students
// }
// console.log(
// updateGrades(10, [
// { firstName: "Jaber", lastName: "jabarbar", grade: 10, type: "regular" },
Expand Down
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<title>Arrays</title>
</head>
<body>
<script src="./arrays.js" type="module" />
<!-- <script src="arrays-basics.js" type="module" /> -->
<!-- <script src="arrays-intermediate.js" type="module" /> -->
<script src="reviewers.js" type="module" />

</body>
</html>
47 changes: 37 additions & 10 deletions reviewers.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,86 @@
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
return reviewer.reviewerName
}
// console.log(getReviewerName(reviewers[0]));
console.log(getReviewerName(reviewers[0]));

/***********************************************************************
- Receives a reviewer object and returns the number of reviews that reviewer has done.
************************************************************************/

function numberOfReviews(reviewer) {
//TODO: ADD YOUR CODE HERE
return reviewer.books.length
}
// console.log(numberOfReviews(reviewers[0]));
console.log(numberOfReviews(reviewers[0]));

/***********************************************************************
- Receives a review title (string) and a reviewer object,
and returns true if the reviewer object has a review that matches the given review title.
Otherwise, it returns false.
- Bonus: uses iteration method .some()
***********************************************************************/
function reviewerHasReview(reviewTitle, reviewer) {

function reviewerHasReview(reviewTitle, reviewer) {
//TODO: ADD YOUR CODE HERE
const cheack = reviewer.books.some((value) =>{

if(value.title === reviewTitle){
return true
}else {
return false
}
});
return cheack

}
// console.log(reviewerHasReview("Becoming", reviewers[0]));
console.log(reviewerHasReview("Becoming", reviewers[0]));

/**************************************************************
- Receives a reviewer name (string) and an array of reviewer objects,
and returns the reviewer object with the same name as the reviewerName provided.
- Bonus: uses iteration method .find()
****************************************************************/
function getReviewerByName(reviewerName, reviewers) {

function getReviewerByName(reviewerName, reviewers) {
//TODO: ADD YOUR CODE HERE
return reviewers.find((value)=> value.reviewerName === reviewerName)
}
// console.log(getReviewerByName("Michelle Obama", reviewers));
console.log(getReviewerByName("Michelle Obama", reviewers));

/**************************************************************
- Receives a review title (string) and an array of reviewer objects,
and returns the reviewer object that has done a review with the review title provided.
- Bonus: uses iteration methods .find() and .some()
****************************************************************/

function getReviewerByReviewTitle(reviewTitle, reviewers) {
//TODO: ADD YOUR CODE HERE
return reviewers.find(value => {
return value.books.some(valuebook =>valuebook.title === reviewTitle);
});
}
// console.log(getReviewerByReviewTitle("The Overstory", reviewers));

console.log(getReviewerByReviewTitle("The Overstory", reviewers));

/**************************************************************
- Receives a query (string) and an array of reviewer objects,
and returns an array of the reviewer objects that contain the query in their name/description.
- Hint: uses string method .includes() and iteration method .filter()
****************************************************************/

function searchReviewers(query, reviewers) {
//TODO: ADD YOUR CODE HERE
}
// console.log(searchReviewers("o", reviewers));
return reviewers.filter((value)=>
( value.reviewerName.toLowerCase().includes(query)) || (value.description.toLowerCase().includes(query))
)
};

console.log(searchReviewers("o", reviewers));