Last active
December 10, 2015 08:06
-
-
Save shadeglare/cb8a58171ab6dc46f7c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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