should.js icon indicating copy to clipboard operation
should.js copied to clipboard

Feature request: pass index and array arguments in matchEach()

Open OttoAllmendinger opened this issue 7 years ago • 1 comments

These arguments are there for JS some(), every(), forEach() etc. They make it easy to test if an array is sorted, for instance:

> [1, 2, 3].every((v, i, arr) => (i === 0) || arr[i-1] < v)
true
> [1, 2, 3, 1].every((v, i, arr) => (i === 0) || arr[i-1] < v)
false

It would be cool if this could be written as

[1, 2, 3, 1].should.matchEach((v, i, arr) => (i === 0) || arr[i-1] < v)

The error message could contain the index at which it failed

OttoAllmendinger avatar Feb 21 '18 13:02 OttoAllmendinger

hi, sorry for silence, this sounds good to me. unfortunately i could not promise any eta for this. i am quite busy at work currently.

btd avatar Feb 24 '18 08:02 btd