Skip to content

Instantly share code, notes, and snippets.

@shadeglare
Last active December 10, 2015 08:06
Show Gist options
  • Save shadeglare/cb8a58171ab6dc46f7c9 to your computer and use it in GitHub Desktop.
Save shadeglare/cb8a58171ab6dc46f7c9 to your computer and use it in GitHub Desktop.
function takeWhile<T>(xs: T[], callback: (x: T, i: number) => boolean): T[] {
let acc: T[] = [];
xs.some((x, i) => {
if (callback(x, i)) {
acc.push(x);
return false;
} else {
return true;
}
});
return acc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment