Repository navigation
Expand file tree
/
Copy pathcallbacks.js
More file actions
89 lines (70 loc) · 1.64 KB
/
Copy pathcallbacks.js
File metadata and controls
89 lines (70 loc) · 1.64 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* eslint-disable */
const altCoins = ['Ripple', 'Tronix', 'Pivx', 'Waves', 'Enjin Coin'];
const firstItem = (arr, cb) => {
cb(arr[0])
}
firstItem(altCoins, firstItem => {
console.log(`The first item is ${firstItem}.`)
})
const getLength = (arr, cb) => {
cb(arr.length);
};
getLength(altCoins, length => {
console.log(`The length of the array is ${length}.`);
});
const last = (arr, cb) => {
cb(arr[arr.length - 1]);
};
last(altCoins, lastCoin => {
console.log(`The last item in the array is ${lastCoin}.`);
});
const sumNums = (num1, num2, cb) => {
cb(num1 + num2);
};
sumNums(5, 10, sum => {
console.log(`The sum is ${sum}.`);
});
const multiplyNums = (num1, num2, cb) => {
cb(num1 * num2);
};
multiplyNums(5, 10, product => {
console.log(`The product is ${product}.`);
});
const contains = (arr, str, cb) => {
const isInArray = () => {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === str) {
return true;
}
} return false;
};
cb(isInArray());
};
contains(altCoins, 'Potcoin', result => {
console.log(result ? 'Potcoin is in the array' : 'Potcoin is not in the array');
});
const removeDuplicates = (arr, cb) => {
var mySet = new Set(arr);
cb([...mySet]);
};
removeDuplicates(altCoins, uniqueCoins => {
console.log(`altCoins with duplicates removed: ${uniqueCoins}`);
});
const forEach = (arr, cb) => {
for (let i = 0; i < arr.length; i++) {
cb(arr[i], i);
}
};
forEach(altCoins, (value, index) => {
console.log(`${value} is at index ${index}.`);
});
/* eslint-enable */
module.exports = {
firstItem,
getLength,
last,
sumNums,
multiplyNums,
contains,
removeDuplicates
}