question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Rule proposal: `prefer-array-some`

See original GitHub issue

Fail

if (array.find(element => element === 'šŸ¦„')) {
}
const foo = array.find(element => element === 'šŸ¦„') ? bar : baz;

Pass

if (array.some(element => element === 'šŸ¦„')) {
}
const foo = array.some(element => element === 'šŸ¦„') ? bar : baz;

Just experienced one few days ago, and kind of follow up for https://github.com/sindresorhus/eslint-plugin-unicorn/issues/730

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
silverwindcommented, May 22, 2020

Maybe Iā€™ve expressed myself badly but the ā€œhardā€ part is remembering to return a truthy value in the callback.

One distinct advantage for-of has over array methods is that it works on all iterables (NodeList, Set, Map), so itā€™s a win-win to use it over array methods.

1reaction
silverwindcommented, May 22, 2020

My issue with array#some and array#every is that I think itā€™s hard to read/understand. I prefer for-of with a break statement because I donā€™t have to think about whether the iterator needs to return true or false to break the loop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules Ā· Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders Ā· File No: S7-30-22 Ā· Comments...
Read more >
sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
Rule proposal : Expiring TODO comments. Rewarded#238created bysindresorhus. 1 pull request. $100.00. Rule proposal: No default parameter options.
Read more >
The Most Curious Rule Proposal in Securities and Exchange ...
I write this post in response to the release (the ā€œProposing Releaseā€) regarding proposed rules (the ā€œProposed Rulesā€) under the InvestmentĀ ...
Read more >
SEC's Proposed Preferential Treatment Rule: Does the Side ...
By Jennifer Kalmanides. On February 9, 2022, the Securities and Exchange Commission (the ā€œSECā€) unveiled a slate of newly proposed rules,Ā ...
Read more >
The SEC's Proposed ā€œPreferential Treatment Ruleā€
On February 9, 2022, the SEC proposed a litany of new rules relating to private fund advisers (the ā€œPrivate Fund Adviser Proposalā€) that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found