Ad
  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar

    What do you mean the wrong way? Isn't that how we're supposed to do it? I mean, there's no way you can access a variable of an inner function without receiving it directly from them (by return) or forcing them to leak the variable onto the global scope (like what you did)

  • Custom User Avatar

    Yes, you pass a sample in the form of two arrays which you have to create yourself to scales.getWeigh() and it returns a response. For example, if ball 1 is the heavy ball, the following will happen:

    measurement = scales.getWeigh([0, 1], [2, 3])        ---> measurement === -1
    measurement = scales.getWeigh([0, 2, 3], [4, 5, 6])  ---> measurement ===  0
    measurement = scales.getWeigh([0, 2, 3], [1, 5, 6])  ---> measurement ===  1
    
  • Custom User Avatar

    Power and root are inverse operations, so your myPow function can with a very small modification be used to compute root instead.

  • Custom User Avatar

    @VladimirZd: You only showed myPow, but you didn't show us how you used that function. That might be an integral part. The numbers may differ at the 12th digit, so it would be interesting to see your actual complete solution.

  • Custom User Avatar

    Nope; I didn't calculate power nor did any other solutions I saw. Your function works " "fine" " , I mean it returns wrong result because of JS floating point issues.

    Passing solutions compute more "directly" the root and eventual remaining floating point issues are handled by an assertFuzzyEquals function bkaes-san wrote for us ( どうもありがとう!Dōmo arigatō! ).

  • Custom User Avatar

    function myPow(n,pow)

    Are-you trying to find the nth power of x ?
    I thought the kata was about the nth root of x.

  • Custom User Avatar

    did you solve this ?

    Uhm, yes, I've published this kata ;). Your solution seems fine, but could you post an actual error message?

  • Custom User Avatar

    That's interesting - could you add your code as comment? Don't forget to mark it as a spoiler and add proper formatting (e.g. indent with 4 spaces).

  • Custom User Avatar

    Can you explain what is the strange result you are talking about? Yes I think it is working, it is not very difficult.

  • Custom User Avatar

    I have added the few tests that you have recommended in the submit tests section.

  • Custom User Avatar

    Thanks, I have updated to say that you only need to truncate and not round the number.

  • Custom User Avatar

    It seems your .isString method doesn't recognize a string created this way: new String('a new String') ie using String as constructor.

    By the way, there're more than 50 other test cases after this one.
    This kata is average ranked 6 kyu, if you really never used JS before may be you should try to solve easier ones before.