Random filter experiment in js
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
// Today I discovered that we can write horrible code in Javascript thanks to the thisArg argument of Array.reduce.filter | |
function myFilter(e) { | |
if (e % 2) { | |
this.val += e; | |
} | |
return e % 3 == 0; | |
} | |
var arr = [1,2,3,4,5,6,7,8,9,10]; | |
ctx = { val: 0 } | |
console.log(arr.filter(myFilter, ctx)); | |
console.log(ctx.val); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment