Array Sum Golfed
a = [1, 2, 3, 6, 9];
sum = eval(a.join`+`);
console.log(sum);
Found myself doing something like this a few times… easy golfed array sum. I saw this over at codegolf stackexchange here.
That whole thread is a great. I plan to post more from there in the future.
toString Hack Obfuscated
x=''+self
j=''
'd1d7a1712345691a7512d427b1da7d9ab7519a4b721a961721d694'
.split``
.map(_=>j+=`x[0x${_}]+`)
console.log(eval(j+'""'))
Yesterday’s snippet saying something else…
It’s simpler than it looks:
x=''+self
// becomes "[object Window]"
j=''
// initialize `j` which will be javascript to pass to `eval`
'd1d7a17123456...'
// this is a list of index values to
// look up in `x` in hexidecimal so that each
// index is a single character
.split``
// split the index values into an array `[0xe, 0x2 ...`
.map(_=>j+=`x[0x${_}]+`)
// map over the index values and write a string like
// this `x[0xe]+x[0x2]+...` into `j`
console.log(eval(j+'""'))
// evaluate `j` with an empty string at the end
// `x[0xe]+x[0x2]+""` and log it out
`