Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 831 Bytes

prefer-array-some.md

File metadata and controls

41 lines (31 loc) · 831 Bytes

Prefer .some(…) over .find(…).

Prefer use Array#some over Array#find when testing array.

Fail

if (array.find(element => element === '🦄')) {
}
const foo = array.find(element => element === '🦄') ? bar : baz;
while (array.find(element => element === '🦄')) {
	array.shift();
}

Pass

if (array.some(element => element === '🦄')) {
}
const foo = array.some(element => element === '🦄') ? bar : baz;
const foo = bar ? array.find(element => element === '🦄') : '';
while (array.some(element => element === '🦄')) {
	array.shift();
}