Skip to content

Instantly share code, notes, and snippets.

@jhyang12345
Last active July 11, 2017 00:00
Show Gist options
  • Save jhyang12345/5c25335c60a5b6032e6f39c9522dbb69 to your computer and use it in GitHub Desktop.
Save jhyang12345/5c25335c60a5b6032e6f39c9522dbb69 to your computer and use it in GitHub Desktop.
//map implementation
function newmap(arr, func) {
var newarr = [];
for(var i = 0; i < arr.length; ++i) {
newarr.push(func(arr[i]));
}
return newarr;
}
function newfilter(arr, func) {
var newarr = [];
for(var i = 0; i < arr.length; ++i) {
if(func(arr[i])) newarr.push(arr[i]);
}
return newarr;
}
console.log(newmap(array, (x) => {
if(typeof x == typeof "")
return x + "$";
else return undefined;
}));
console.log(newfilter(filterarray, (x) => {
return x;
}));
var strarray = ["asdfzxcv", "asdf", "zxc", "qwersdfg"];
console.log(newfilter(strarray, (x) => {
return x.length > 3;
}));
//!! converting a value to boolean and inverting it twice
//javascript was originally called livescript but before shipping the name was changed to Javascript, which was said to be a
//ploy to make javascript more popular
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment