Skip to content

Instantly share code, notes, and snippets.

@amyhenning
Last active September 1, 2018 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyhenning/3bd81077f333566cd8647f7188f181b8 to your computer and use it in GitHub Desktop.
Save amyhenning/3bd81077f333566cd8647f7188f181b8 to your computer and use it in GitHub Desktop.
Built the map method in JS
"use strict";
var _ = {
// Implements:
// https://lodash.com/docs#map
map: (array, callback) => {
return callback(array);
}
}
// Define a method that multiplies the input by 10
function multiplyBy10(value) {
let result = [];
for (let i = 0; i < value.length; i++) {
result.push(value[i] * 10);
}
return (result);
}
const value = _.map([1, 2, 3], multiplyBy10);
// value => [10, 20, 30]
console.log(value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment