Created
November 6, 2019 12:28
-
-
Save DanShappir/870807aadde54d9154ed4f9bef127f7f to your computer and use it in GitHub Desktop.
Simple slice generator
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
function* slice(src, start, finish = Number.MAX_SAFE_INTEGER) { | |
let index = 0; | |
for (const value of src) { | |
if (index >= finish) { | |
break; | |
} | |
if (index >= start) { | |
yield value; | |
} | |
++index; | |
} | |
} |
You've got a \t
instead of two spaces on line 2.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why
break
instead ofreturn
?