⬅︎ Back to Sort a JavaScript array by some boolean operation
Hi there!Instead of using Number() on both includes-results, you can just use "itemB.labels.includes('foo') - itemA.labels.includes('foo')".This works because minus will convert both sides to a number anyway before subtracting.Best regards
You're right! I had forgotten about that. I updated the blog post. Truth be told, I'm not sure it's an improvement because it feels like a quirk whereas casting to a number type feels a bit more "commonstream".
Comment
Hi there!
Instead of using Number() on both includes-results, you can just use "itemB.labels.includes('foo') - itemA.labels.includes('foo')".
This works because minus will convert both sides to a number anyway before subtracting.
Best regards
Replies
You're right! I had forgotten about that. I updated the blog post.
Truth be told, I'm not sure it's an improvement because it feels like a quirk whereas casting to a number type feels a bit more "commonstream".