DEV Community

Mikayil
Mikayil

Posted on

Flaw in CodeWars code?

I had this challenge:

Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty ( zero length ).
Hint for R users:
The length of string is not always the same as the number of characters
For example: (Input1, Input2) --> output
("1", "22") --> "1221"
("22", "1") --> "1221"

And my solution was:
const solution = (a, b) => {return a.length < b.length ? a+b+a : b+a+b}
Then I found this among accepted solutions:
const solution = (a, b) => a < b ? a + b + a : b + a + b;
Which is wrong in when you pass "true" or "false" or both of them:
solution("u","false") -> "falseufalse"
solution("true","false") -> "falsetruefalse"
solution("true","sample") -> "sampletruesample"

I am doubtful now about the platform. Maybe it also accepted my solutions when they were wrong...

Top comments (1)

Collapse
 
madjosz profile image
Madjosz

This kata is one of the oldest on Codewars (created 2012) and for years it had only two fixed tests which are of course not sufficient to test the validity of a solution, that's why these wrong solutions are shown there. In the meantime the tests got updated with a proper random test suite but not all invalid solutions have been invalidated as this would be a very CPU expensive job to rerun all 15k solutions.