Created
January 22, 2016 07:37
-
-
Save shuding/6b8fb023f63fc8fb4f94 to your computer and use it in GitHub Desktop.
An one-line range function with JavaScript ES6, like Python
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
const range = (s, t = 0, a = 1) => [...Array(Math.abs(s - t))].map((x, i) => Math.min(s, t) + i * a).filter(x => x < Math.max(s, t)); | |
console.log(range(5)); | |
console.log(range(2, 5)); | |
console.log(range(0, 5, 2)); | |
// node.js: please run with `node --harmony_default_parameters --harmony range.js` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment