Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
x is the variable in the arrow function expression that is immediately called with the argument h-d.
https://developer.mozilla.org/en-US/docs/Glossary/IIFE
In this case i represents the index of the last element in the array, which is 2 for the initial array.
That's bitwise AND.
See here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND
In this case it's functioning as a shorthand to check to see if a number is odd. In binary, odd integers always end in 1, while even integers always end in 0. So if n is even then n&1 evaluates to 0, and if n is odd then n&1 evaluates to 1.
Click the "View Solution" link under my comment.
This comment is hidden because it contains spoiler information about the solution
I definitely get your point, as the Codewars voting system tends to favor code that's concise and clever over actual best practices. However, I don't actually think this is hard to read if you're in the habit of writing functional JavaScript. If the procedural approach is what you're comfortable with then of course it's easier to read. At any rate, I'd be curious to see a functional solution that's more readable than this. I took a crack at it here using recursion, but I think the readability is about the same.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
5 kyu math problem, 8 kyu coding exercise.
Fair critique, thanks. One of the limitations of codewars is that pretty code gets upvoted more than efficient code.
Yes, that's stated in the details of the kata.
Fixed.
If I'd submitted a brute force you never would have seen it because it would have been lost in the sea of thousands of other brute force solutions (including yours). I had no reason to save it, otherwise I'd post it here for you, but I promise there was nothing interesting about it.
Fixed it.
Loading more items...