Skip to content

Instantly share code, notes, and snippets.

@DanShappir
Created November 6, 2019 12:28
Show Gist options
  • Save DanShappir/870807aadde54d9154ed4f9bef127f7f to your computer and use it in GitHub Desktop.
Save DanShappir/870807aadde54d9154ed4f9bef127f7f to your computer and use it in GitHub Desktop.
Simple slice generator
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;
}
}
@Sequoia
Copy link

Sequoia commented Jan 16, 2020

Why break instead of return?

@xehpuk
Copy link

xehpuk commented Jan 20, 2021

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