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
44 changes: 32 additions & 12 deletions arrays-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,66 @@
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((v, i) => {
// console.log(v);
// });
// }
// 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) {
// let evenNumb = arr.every((value, index) => {
// return value % 2;
// });
// console.log(evenNumb);
// }
// 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) {
// return arr.reverse();
// }

// logArrayBackwards(["one", "two", "three", "four"]);
// 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) {}
// function logLastItem(arr) {
// let last = arr[arr.length - 1];
// console.log(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 (i = 0; i < arr.length; i = i + chunkSize) {
let sum = arr.slice(i, i + chunkSize);
// return chunkSize;
console.log(sum);
}
}

// logArrayInChunks([1, 2, 3, 4, 5, 6, 7, 8, 9], 3);
logArrayInChunks([1, 2, 3, 4, 5, 6, 7, 8, 9], 3);
137 changes: 90 additions & 47 deletions arrays-intermediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
**************************************************************/
function sumArray(numbers) {
//TODO: Add your code here
let sumArr = numbers.reduce((acc, curr) => {
return acc + curr;
});
return sumArr;
// why would anyine use consol.log(sumarr) it to look for an undefoed value?
}
// console.log(sumArray([4, 3, 2, 5, -10]));

console.log(sumArray([4, 3, 2, 5, -10]));

/**************************************************************
Task 2:
Expand All @@ -17,10 +23,14 @@ function sumArray(numbers) {
**************************************************************/
function findFirstStringStartingWithLetter(letter, strings) {
//TODO: Add your code here
let findFirst = strings.find((value, index) => {
return value.startsWith(letter.toUpperCase());
});
return findFirst;
}
// console.log(
// findFirstStringStartingWithLetter("h", ["Memory", "Hello", "Happy"])
// );
console.log(
findFirstStringStartingWithLetter("h", ["Memory", "Hello", "Happy"])
);

/**************************************************************
Task 3:
Expand All @@ -31,16 +41,20 @@ function findFirstStringStartingWithLetter(letter, strings) {
**************************************************************/
function isPresentIncluded(presentName, presents) {
//TODO: Add your code here
let present = presents.map((value, index) => {
return value.toLowerCase().includes(presentName);
});
return present;
}
// console.log(
// isPresentIncluded("puzzle", [
// "Sparkling Surprise",
// "Enchanted Elegance",
// "Whimsical Wonder",
// "Joyful Jingle",
// "Puzzle",
// ])
// );
console.log(
isPresentIncluded("puzzle", [
"Sparkling Surprise",
"Enchanted Elegance",
"Whimsical Wonder",
"Joyful Jingle",
"Puzzle",
])
);

/**************************************************************
Task 4:
Expand All @@ -51,21 +65,23 @@ function isPresentIncluded(presentName, presents) {
**************************************************************/
function sortStudentsAlphabetically(students) {
//TODO: Add your code here

return students.sort();
}
// console.log(
// sortStudentsAlphabetically([
// "Eve",
// "Jasmia",
// "Husnia",
// "Grace",
// "Bob",
// "Charlie",
// "Alice",
// "Dave",
// "Um abbas",
// "Frank",
// ])
// );
console.log(
sortStudentsAlphabetically([
"Eve",
"Jasmia",
"Husnia",
"Grace",
"Bob",
"Charlie",
"Alice",
"Dave",
"Um abbas",
"Frank",
])
);

/**************************************************************
Task 5:
Expand All @@ -79,11 +95,25 @@ function sortStudentsAlphabetically(students) {
**************************************************************/
function separateOddEven(numbers) {
//TODO: Add your code here
numbers.forEach((value) => {
let odd = [];
let even = [];
if (value % 2 === 0) {
odd.pop(value);
even.push(value);
console.log(`the arr is even ${even}`);
} else {
odd.push(value);
even.pop(value);
console.log(`the arr is odd ${odd}`);
}
});
return numbers;
}
// console.log(separateOddEven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
console.log(separateOddEven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));

/**************************************************************
Task 6:
Task 6:
Create a function that takes two parameters: a code that represents an item, and an array of item codes, then removes the item with the given code from the system.
- Hint: Use the filter method.
- e.g
Expand All @@ -101,15 +131,18 @@ function separateOddEven(numbers) {
**************************************************************/
function removeItem(code, items) {
//TODO: Add your code here
return items.filter((item) => {
return item.code !== code;
});
}
// console.log(
// removeItem("#153", [
// { code: "#153", name: "Ball" },
// { code: "#147", name: "Scissors" },
// { code: "#249", name: "Pillow" },
// { code: "#149", name: "Tissue" },
// ])
// );
console.log(
removeItem("#153", [
{ code: "#153", name: "Ball" },
{ code: "#147", name: "Scissors" },
{ code: "#249", name: "Pillow" },
{ code: "#149", name: "Tissue" },
])
);

/**************************************************************
Task 7:
Expand Down Expand Up @@ -158,14 +191,24 @@ Task 7:
**************************************************************/
function updateGrades(curve, students) {
//TODO: Add your code here
let updatedStudents = [...students];
updatedStudents.map((student) => {
if (student.type === "nerd") {
student.grade - curve;
} else {
student.grade + curve;
}
return student;
});
return updatedStudents;
}
// 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" },
])
);
Empty file added arrays.js
Empty file.
19 changes: 10 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Arrays</title>
</head>
<body>
<script src="./arrays.js" type="module" />
</body>
</html>
</head>
<body>
<!-- <script src="./arrays.js" type="module" /> -->
<script src="arrays-intermediate.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion reviewers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ console.log("🚀 ~ file: reviewers.js:2 ~ reviewers:", reviewers);
***********************************************************************/
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.
Expand Down