This Kata is too dificult for level 7 kyu. The description is also very poor.
I see my flaw. I need to take into account the position of the element in the original array. That way the sequence between say two i in the result becomes the longest.
When I get the following input, the expected is what the tests tell me and the "instead got" is my solution. The expected solution expects the second i before the second a, even the second a appears before the second i in the input.
Input ['i', 'a', 'd', 'h', 'f', 'j', 'a', 'k', 'j', 'c', 'i', 'e', 'd', 'i', 'a', 'b', 'i', 'h', 'e', 'h', 'g', 'g', 'g', 'j', 'i', 'k', 'k', 'k', 'b', 'f']
^ ^ ^ ^
Expected: ['i', 'a', 'd', 'h', 'f', 'j', 'k', 'c', 'e', 'b', 'g', 'i', 'a', 'd', 'h', 'f', 'j', 'k', 'e', 'b', 'g', 'i', 'a', 'h', 'j', 'k', 'g', 'i', 'k', 'i'],
^ ^ ^ ^
instead got: ['i', 'a', 'd', 'h', 'f', 'j', 'k', 'c', 'e', 'b', 'g', 'a', 'j', 'i', 'd', 'h', 'e', 'g', 'k', 'b', 'f', 'i', 'a', 'h', 'g', 'j', 'k', 'i', 'k', 'i']
^ ^ ^ ^
Even the second j should be before the second i.
I keep getting an error
TypeError: Cannot read property '9' of undefined
at transitionFunction (test.js:127:56)
at machine (test.js:10:50)
at Context.<anonymous> (test.js:144:21)
when calling the transitionFunction, which is really annoying. My solution works for the given tests and I cannot see what is wrong with me calling the way I do.
Since the two arguments are both booleans we can use them directly when comparing. This solution asks if I'm employed and (&&) not (!) on vacation. Since this is Ruby, the last executed line in a method is automatically returned.
How in the hell does this work?
This was not a 7 kyu in my opinion.
I knew Ruby could do it in less than 40 characters! Damn!
I'd like to add that not adding the 'return' is more idiomatic Ruby (& also following the Ruby style guide, see https://rubystyle.guide/#no-explicit-return).
yep, but it's optional
... and it didn't work, so I took the liberty of changing the initial solution, so that people can actually press "Run Sample Tests" ;-)
Ruby has an implicit return for the last statement in methods.
nope, not in ruby