Created
September 25, 2017 12:10
-
-
Save miladvafaeifard/8332b27ec8cf6e2b9dc12291bc6d8c2e to your computer and use it in GitHub Desktop.
JS Bin flatmap function with reduce functional programming // source http://jsbin.com/kujupip
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="flatmap function with reduce functional programming"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function flatmap(arr, fn){ | |
return arr.reduce((flatArr, curr) => { | |
return flatArr.concat(fn(curr)); | |
}, []); | |
} | |
console.log(flatmap([1,2,3], n => [n, n*n])); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
function flatmap(arr, fn){ | |
return arr.reduce((flatArr, curr) => { | |
return flatArr.concat(fn(curr)); | |
}, []); | |
} | |
console.log(flatmap([1,2,3], n => [n, n*n]));</script></body> | |
</html> |
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
function flatmap(arr, fn){ | |
return arr.reduce((flatArr, curr) => { | |
return flatArr.concat(fn(curr)); | |
}, []); | |
} | |
console.log(flatmap([1,2,3], n => [n, n*n])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment