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
30 lines (22 loc) · 744 Bytes
/
Copy pathproject-4.js
File metadata and controls
30 lines (22 loc) · 744 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
/* eslint-disable no-confusing-arrow */
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) => cb(x + y);
const multiplyNums = (x, y, cb) => cb(x * y);
const contains = (collection, item, cb) => collection.indexOf(item) !== -1 ? cb(true) : cb(false);
const removeDuplicates = (collection, cb) => {
const seen = {};
return cb(collection.filter((item) => {
return seen.hasOwnProperty(item) ? false : (seen[item] = true);
}));
};
module.exports = {
getFirstItem,
getLength,
getLastItem,
sumNums,
multiplyNums,
contains,
removeDuplicates
};