Last active
May 9, 2016 14:39
-
-
Save gusaaaaa/5664488 to your computer and use it in GitHub Desktop.
ECMAScript 5.1 tricks
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
// one-liner to build a sequence of numbers | |
// source: http://ariya.ofilabs.com/2013/01/es6-and-array-comprehension.html | |
Array.apply(0, Array(3)).map(function(x, y) { return y }); // [0, 1, 2] | |
// one-liner to filter elements | |
// source: http://ariya.ofilabs.com/2013/01/es6-and-array-comprehension.html | |
[1,4,2,3,-8].filter(function(i) { return i < 3 }); // [1, 2, -8] | |
// one-liner to filter out even numbers | |
// source: http://ariya.ofilabs.com/2013/01/es6-and-array-comprehension.html | |
[0,1,2,3,4,5,6].filter(function(x,y) { return y & 1 }); | |
// one-liner to filter out vowels | |
// source: http://ariya.ofilabs.com/2013/01/es6-and-array-comprehension.html | |
['X','A','B','E','Z'].filter(function(s) { return 'AEUIO'.indexOf(s) < 0 }); | |
// array-like structure to array | |
a = { 0: 'A', 1: 'B', length: 2 } | |
[].slice.call(a) // ['A', 'B'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think Mustafa is a pretty cool guy. Eh does SEO and doesn’t afraid of anything.