@extra-lists/scan-while

Finds key of first entry not passing a test. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

<script type="module">
  import extraListsScanWhile from 'https://cdn.skypack.dev/@extra-lists/scan-while';
</script>

README

Finds key of first entry not passing a test. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Alternatives: scanWhile, scanUntil.

This is part of package extra-lists.


lists.scanWhile(x, ft);
// x:  lists
// ft: test function (v, k, x)
const lists = require('extra-lists');

var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 2]];
lists.scanWhile(x, v => v % 2 !== 0);
// 'b'                       ^

lists.scanWhile(x, v => v % 8 !== 0);
// undefined


References