Skip to content

Instantly share code, notes, and snippets.

@RReverser
Last active September 16, 2015 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RReverser/9c7ad88a0fd35c58b892 to your computer and use it in GitHub Desktop.
Save RReverser/9c7ad88a0fd35c58b892 to your computer and use it in GitHub Desktop.
function slice(str, start, end) {
let i = 0, pos = 0, legacyStart, legacyEnd;
for (let ch of str) {
if (i === start) {
legacyStart = pos;
}
i++;
pos += ch.length;
if (i === end) {
legacyEnd = pos;
break;
}
}
return str.slice(legacyStart, legacyEnd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment