Skip to content

Instantly share code, notes, and snippets.

@BruJu
Created February 21, 2020 14:53
Embed
What would you like to do?
Random filter experiment in js
// 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