Last active
July 11, 2017 00:00
-
-
Save jhyang12345/5c25335c60a5b6032e6f39c9522dbb69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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