Skip to content

Commit 19ddbd0

Browse files
committed
Completed Project 4
1 parent 7b57de1 commit 19ddbd0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/project-4.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
const getFirstItem = (collection, cb) => {
22
// invoke the callback function and pass the first item from the collection in as an argument
3+
cb(collection[0]);
34
};
45

56
const getLength = (collection, cb) => {
67
// Write a function called getLength that passes the length of the array into the callback
8+
cb(collection.length);
79
};
810

911
const getLastItem = (collection, cb) => {
1012
// Write a function called getLastItem which passes the getLastItem item of the array into the callback
13+
cb(collection[collection.length - 1]);
1114
};
1215

1316
const sumNums = (x, y, cb) => {
1417
// Write a function called sumNums that adds two numbers and passes the result to the callback
18+
cb(x + y);
1519
};
1620

1721
const multiplyNums = (x, y, cb) => {
1822
// Write a function called multiplyNums that multiplies two numbers and passes the result to the callback
23+
cb(x * y);
1924
};
2025

2126
const contains = (collection, item, cb) => {
2227
// Write a function called contains that checks if an item is present inside of the given array.
2328
// Pass true to the callback if it is, otherwise pass false
29+
cb(collection.includes(item));
2430
};
2531

2632
const removeDuplicates = (collection, cb) => {
2733
// Write a function called removeDuplicates that removes all duplicate values from the given array.
2834
// Pass the array to the callback function. Do not mutate the original array.
35+
const arr = [];
36+
for (let i = 0; i < collection.length; i++) {
37+
if (!arr.includes(collection[i])) {
38+
arr.push(collection[i]);
39+
}
40+
}
41+
cb(arr);
2942
};
3043

3144
module.exports = {

0 commit comments

Comments
 (0)