Skip to content

Instantly share code, notes, and snippets.

@coproduto
Created May 3, 2017 17:27
Show Gist options
  • Save coproduto/ef71be974deec8d57acaf64214890433 to your computer and use it in GitHub Desktop.
Save coproduto/ef71be974deec8d57acaf64214890433 to your computer and use it in GitHub Desktop.
function rangeFromZero(end) {
return [...Array(end).keys()];
}
function exclusiveRange(start, end) {
if (end === undefined) {
return rangeFromZero(start);
}
if (end > start) {
return rangeFromZero(end - start).map(x => x + start);
}
return [];
}
function inclusiveRange(start, end) {
if (end === undefined) {
return rangeFromZero(start+1);
}
return exclusiveRange(start, end+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment