forked from bloominstituteoftechnology/Basic-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-4.js
More file actions
45 lines (38 loc) · 823 Bytes
/
project-4.js
File metadata and controls
45 lines (38 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const getFirstItem = (collection, cb) => {
cb(collection[0]);
};
const getLength = (collection, cb) => {
cb(collection.length);
};
const getLastItem = (collection, cb) => {
cb(collection[collection.length - 1]);
};
const sumNums = (x, y, cb) => {
const numSummed = x + y;
cb(numSummed);
};
const multiplyNums = (x, y, cb) => {
const numProduct = x * y;
cb(numProduct);
};
const contains = (collection, item, cb) => {
cb(collection.includes(item));
};
const removeDuplicates = (collection, cb) => {
const itemsChecked = [];
collection.forEach((item, index) => {
if (itemsChecked.indexOf(item) === -1) {
itemsChecked.push(item);
}
});
cb(itemsChecked);
};
module.exports = {
getFirstItem,
getLength,
getLastItem,
sumNums,
multiplyNums,
contains,
removeDuplicates
};