The top voted Javascript solution is wrong. It fails this simple test:
Test.assertEquals(amicableNumbers(8,7), false);
Instead it returns true, as it only tests for amicability in one direction. Although the proper factors of 8 add up to 7 (1 + 2 + 4 = 7), the only proper factor of 7 is (1).
I marked this as an issue with the kata, since the kata test cases only require that the solution tests for amicability in one direction. What is missing are tests like this:
// For some nTest.assertEquals(amicableNumbers(n,sumOfProperDivisors(n)), false);
Test.assertEquals(amicableNumbers(sumOfProperDivisors(n),n), false);
Description should be language-agnostic
JS: Random test rarely generate descriptive numbers.
At least in JS: missing edge case tests to distinguish between
sum < num
andsum <= num
(for instance,4
and496
).30 laps on softs give
46.12772059958206
seconds, that's more than 1 pit stop takes.The top voted Javascript solution is wrong. It fails this simple test:
Instead it returns true, as it only tests for amicability in one direction. Although the proper factors of 8 add up to 7 (
1 + 2 + 4 = 7
), the only proper factor of 7 is (1
).I marked this as an issue with the kata, since the kata test cases only require that the solution tests for amicability in one direction. What is missing are tests like this: