This one is not safe as it will mutate the array coming in (it is not a pure function). It is better to spread it into a new array and return the first item in that array and leave the original one untouched.
It'd be infinitely more useful to put a diagram about the various things. It's still a paragraph vaguely describing the requirement rather than explicitly stating how it is calculated.
The clue part is not a clue, it's an essential part of the information (otherwise how should anyone figure out what even is the task without looking at the test cases?). But then this paragraph is pretty useless at explaining the task, so it really should be rewritten. e.g:
They are all connected to the golden ratio when the length and height represent the golden ratio, ie/ length = 13 and height = 8.
To calculate this you need to find the validator that matches the hash mod total stake of all validators.
Can the description be more useless than this?
The hash is 4 bytes while the array consists of 2 bytes of numbers, so what does it mean to mod them? (Doing it the obvious way doesn't lead to anything.) What does it mean for a validator to "match"? Why is chosenValidator("21e66e37e", [25,5,20,25,20,5]) equal to 4 if both 2 and 4 are 20? There are so many questions.
I thought 120 should be included as an incrementing number... Now I realise the trailing "0" should only come after "9"... Hence my hack arr.join('') !== '120'
While people are rightfully pointing out why this solution is not recommended, I enjoyed seeing a new way to solve the problem.
This one is not safe as it will mutate the array coming in (it is not a pure function). It is better to spread it into a new array and return the first item in that array and leave the original one untouched.
@Voile I completely agree with the usefulness of a diagram and I did consider it, however overall I thought it would make things too obvious and easy.
The user did say it was "related" to the golden ratio, and the kata is flagged as "puzzle".
It'd be infinitely more useful to put a diagram about the various things. It's still a paragraph vaguely describing the requirement rather than explicitly stating how it is calculated.
@Voile, I'll try and think of another way of writing this, thank you for the feedback
@Voile, I've updated the description, let me know if I missed anything,thank you
Thank you @Voile for the feedback, I will fix this
The
clue
part is not a clue, it's an essential part of the information (otherwise how should anyone figure out what even is the task without looking at the test cases?). But then this paragraph is pretty useless at explaining the task, so it really should be rewritten. e.g:How is
13 / 8
the golden ratio (1.618033...
)?Can the description be more useless than this?
The hash is 4 bytes while the array consists of 2 bytes of numbers, so what does it mean to
mod
them? (Doing it the obvious way doesn't lead to anything.) What does it mean for a validator to "match"? Why ischosenValidator("21e66e37e", [25,5,20,25,20,5])
equal to4
if both2
and4
are20
? There are so many questions.Very cool
Remember you only need to return a boolean, so you don't really need mathematics at all, simply an understanding of probability
Just removed the hack, this version should be deleted
I thought 120 should be included as an incrementing number... Now I realise the trailing "0" should only come after "9"... Hence my hack
arr.join('') !== '120'