Skip to content

Instantly share code, notes, and snippets.

@danielcaldas
Created April 11, 2018 15:01
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 danielcaldas/bc5d7144cc2ee08bd484890334e08884 to your computer and use it in GitHub Desktop.
Save danielcaldas/bc5d7144cc2ee08bd484890334e08884 to your computer and use it in GitHub Desktop.
/**
* Drops array elements while specified condition is met
* @param {Array.<T>} array
* @param {Function} cb condition to drop elements
* @returns {Array.<T>} returns array tail of resulting operation
*/
function dropWhile(array, cb) {
const n = array.length;
let i = 0;
for (; i < n; i++) {
if (!cb(array[i])) {
break;
}
}
return array.slice(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment