0.1.0 • Published 9 years ago
roundpen-array-prototype-find v0.1.0
ES6 Array.prototype.find
ponyfill
var find = require('roundpen-array-prototype-find')
find.call([ 1, 3, 5, 7, 9 ], function(x) {
return x > 4
}) // => 5
find.call([ 1, 3, 5, 7, 9 ], function(x, index) {
return index === 3
}) // => 7
find.call([ 1, 3, 5, 7, 9 ], function(x, index, list) {
return index === list.length - 1
}) // => 9
find.call([ 1, 3, 5, 7, 9 ], function(x) {
return x > 100
}) // => undefined
function aPredicate(x) {
return true
}
find.call([ ], aPredicate) // => undefined
try {
find.call([ ], null)
} catch (e) {
e instanceof TypeError // => true
}
try {
find.call(null, aPredicate)
} catch (e) {
e instanceof TypeError // => true
}
try {
find.call(undefined, aPredicate)
} catch (e) {
e instanceof TypeError // => true
}
0.1.0
9 years ago