-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
48 lines (39 loc) · 1.16 KB
/
map.js
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
// Function Definition
// Our map function will take in two arguments:
// An array to map
// A callback function
// The map function will return a new array based on the results of the callback function.
const words = ["ground", "control", "to", "major", "tom"];
const map = function(array, callback) {
const results = [];
for (let item of array) {
results.push(callback(item));
}
return results;
}
const results1 = map(words, word => word[0]);
const eqArrays = function (firstArray, secondArray) {
let count =0;
for (let i = 0; i <=firstArray.length-1; i ++) {
if (firstArray[i] === secondArray[i]) {
count +=1;
}
}
if (count === firstArray.length) {
return true;
} else {
return false;
}
}
const assertArraysEqual = function(actual, expected) {
let new1 = eqArrays(actual,expected);
if (new1 === true) {
console.log(` ✅✅✅ Assertion Passed: ${actual} === ${expected}`);
} else {
console.log(` 🚫🚫🚫 Assertion Failed: ${actual} !== ${expected}`);
}
};
assertArraysEqual(results1,['g','c','t','m','t']);
assertArraysEqual(results1,['g','c','t','m']);
assertArraysEqual(results1,[]);
module.exports = map;