Skip to content

Instantly share code, notes, and snippets.

@BruJu
Created February 21, 2020 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruJu/e9bb7aa4c2c22b63970fbc44a9f52e89 to your computer and use it in GitHub Desktop.
Save BruJu/e9bb7aa4c2c22b63970fbc44a9f52e89 to your computer and use it in GitHub Desktop.
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