UNPKG

@mxmitch/lotide

Version:

A mini clone of the [Lodash](https://lodash.com) library.

57 lines (50 loc) 1.39 kB
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; }; //TESTING MAP const results1 = map(words, word => word[0]); console.log(results1); const results2 = map(words, word => word.length); console.log(results2); const results3 = map(words, word => word + word); console.log(results3); //Function to test if arrays are equal const eqArrays = function(array1, array2) { if (array1.length !== array2.length) { return false; } else { for (let i = 0; i < array1.length; i++) { if (typeof array1[i] !== typeof array2[i]) { return false; } } for (let i = 0; i < array1.length; i++) { if (array1[i] !== array2[i]) { return false; } } return true; } }; //Function to assert if arrays are equal const assertArraysEqual = function(actual, expected) { if (eqArrays(actual, expected)) { console.log(`✅✅✅ Assertion Passed: ${actual} === ${expected}`); } else { console.log(`🛑🛑🛑 Assertion Failed: ${actual} !== ${expected}`); } }; // TEST CODE assertArraysEqual(results1, ['g', 'c', 't', 'm', 't']); assertArraysEqual(results2, [6, 7, 2, 5, 3]); assertArraysEqual(results3, ['groundground', 'controlcontrol', 'toto', 'majormajor', 'tomtom' ]);