The default behaviour of Array.prototype.find is to return the first matching value or undefined if not found. Collections.js returns -1 instead of undefined, which causes an unexpected issue with truthiness and coercion:
Standard behaviour:
[].find(a => true) // undefined
!![].find(a => true) // false
Collections.js behaviour:
[].find(a => true) // -1
!![].find(a => true) // true
I'm only curious why this decision was made.
The default behaviour of
Array.prototype.findis to return the first matching value orundefinedif not found. Collections.js returns-1instead ofundefined, which causes an unexpected issue with truthiness and coercion:Standard behaviour:
Collections.js behaviour:
I'm only curious why this decision was made.