-
-
Save defims/0c32e976cf65acb4e411f3e633c429c7 to your computer and use it in GitHub Desktop.
Array.prototype.reduceRight
This file contains hidden or 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
// 109 bytes, 153 including 'Array.prototype.reduceRight=[].reduceRight||' ... | |
function ( | |
a, // callback | |
b // initialValue and result | |
){ | |
for ( | |
var c = this, // 'this' shortcut | |
d = c.length + 1, // iterator | |
e; // 'undefined' and flag for trailing "holes" in 'c' | |
d--; | |
) | |
b = d in c ? a(b, c[d], d, e = c) : e || b !== e ? b : c[d -= d - 1 in c]; | |
return b | |
} |
This file contains hidden or 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
export function(a,b){for(var c=this,d=c.length+1,e;d--;)b=d in c?a(b,c[d],d,e=c):e||b!==e?b:c[d-=d-1 in c];return b} |
This file contains hidden or 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Sebastien P. https://twitter.com/#!/_sebastienp | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or 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
{ | |
"name": "Array.prototype.reduceRight", | |
"description": "ES5 Array.prototype.reduceRight polyfill", | |
"keywords": [ "ES5", "array", "reduceRight", "polyfill" ], | |
"version": "0.1.0" | |
} |
This file contains hidden or 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> | |
<title>Foo</title> | |
<div>Expected value: <b>16</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
Array.prototype.reduceRight=function(a,b){for(var c=this,d=c.length+1,e;d--;)b=d in c?a(b,c[d],d,e=c):e||b!==e?b:c[d-=d-1 in c];return b} | |
document.getElementById( "ret" ).innerHTML = [,,,1,2,,3,,,,,,].reduceRight(function(a,b){return a+b},10) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment