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 solution is off by 1 for every perfect square greater than 1.
Thanks, that one took me a while. Thought it was looking for a particular error message!
Ok, so if anyone is wondering why your JavaScript code is failing the tests for non-decimal strings it's because you're not actually supposed to throw an error (despite what the description says). In the event of an empty or non-decimal string simply return false.
Just figured out that this is due to JavaScript's built-in limitations. Try printing the result of dividing any odd number with more than 16 digits and you'll see it returns an integer rather than a number ending in .5.
I had assumed that some of the tests would involve very large numbers that would render a brute force approach futile and so I spent a fair amount of time researching Faulhaber's Formula and algorithms for calculation of Bernoulli numbers. While taking a pause I tried the simple for loop approach on a lark and was shocked to see it pass all the tests.
It's always satisfying to see ones points go up but I think the tests need to require a more optimized solution in order for this to be 4 kyu.
Great Kata. My first introduction to the concept of Finite State Machines!
This comment is hidden because it contains spoiler information about the solution
Ok. Just a string. Now if only I knew what the function is expected to return in case of an empty input array...
I hadn't checked with the sample tests. I'd just read the instructions which lists several formats for acceptable results, of which one appears to be an array of arrays [ [numer_1, denom_1] , ... [numer_n, denom_n] ]. I've only been learning Javascript for a few months and am not sure whether (numer_1, D)(number_2, D)... simply means a string of literal parentheses and commas concatenated with the values of the numerators and lcd or whether this is a special structure that I haven't yet learned about.
Question regarding the required syntax for the solution (Javascript). My solution returns the correct numerators and denominators but is rejected due to syntax. Specifically, I wrote the function to return an array of 2-item arrays (each one consisting of the numerator and least common denominator). I see that instead of returning, e.g. [[6, 12], [3, 12], [4, 12]], my function should return (6, 12), (3, 12), (4, 12).
My question is are the expected parentheses and commas simply string literals? Or is this some data structure with which I'm not yet familiar?