Skip to content

1000ch/array-find

Repository files navigation

array-find Build Status

Polyfill for Array.prototype.find.

testling badge

Usage

Functionally:

var find = require('@1000ch/array-find');

function isPrimary(item, index, array) {
  var start = 2;
  while (start <= Math.sqrt(number)) {
    if (number % start++ < 1) {
      return false;
    }
  }
  return (number > 1);
}

console.log(find([4, 5, 8, 10], isPrimary));
// => 5

From Array object:

require('@1000ch/array-find/shim');

var array = [4, 5, 8, 10];

console.log(array.find(isPrimary));
// => 5

License

MIT: http://1000ch.mit-license.org

About

Polyfill for Array.prototype.find

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •