Ad
  • Custom User Avatar

    I thought it wasn't allowed to use eval... meh. :(

  • Custom User Avatar

    Now I understood what you meant when saying that I can't work my way through the digits of a number in that way. I see now that JavaScript doesn't support what I was attempting, so I changed a bit and now works!

    Hahaha, cheers!

  • Custom User Avatar

    I don't get it, why not? It seems just fine for my.

    Strangely this works fine for Java.

    I even tried to change the "for in" loop to a traditional "for" loop and still nothing. Maybe is something in JavaScript that doesn't support ? :(

  • Default User Avatar

    I'm not being able to pass on the test but I'm pretty sure my code is right, could someone help me see what is happening ?

    function narcissistic( value ) {
      var i, a, b;
      if (value < 10){
        return true;
      }
      else{
        for(i in a=b=value)b-=Math.pow(a[i],a.length)
        return(!b);
      }
    }
    

    See, I get reproved in the test case for 153 ("Test Failed: 153 is narcissistic"), but in my function goes like this:

    for(i in a=b=153)b-=Math.pow(a[i],a.length)
    

    wich goes 3 times, since a.length is 3 so:

    #1º) 153 - Math.pow(1,3) = 153 - 1 = 152

    #2º) 154 - Math.pow(5,3) = 152 - 5^3 = 27

    #3º) 27 - Math.pow(3,3) = 27 - 3^3 = 0

    Then again, my function returns (!b), since b = 0, !0 = true

    Why my code is not being accepted ?

    Hope someone help me out, cheers!

  • Custom User Avatar

    Ok, I see what I did now.. ahahaha, I was "printing" instead of "returning".
    shame on me!

    Thanks anyway.

  • Custom User Avatar

    I'm sorry ogryzek, since you've marked your reply as a spoiler and I didn't solve the problem because I'm getting the error, I can't un-flag it, so I would appreciate if you could tell me a hint in a different way.

    Cheers ! =)

  • Default User Avatar

    While working out with the Instructions and Output tabs there's this:

    "Tip: You can press Cmd + I to toggle between Instructions and Output tabs."

    I don't know if this site was design only for Mac users, but in Linux and Windows we don't have the "Cmd" button.

    I suggest you guys change to a more universal pattern.

    Anyway, I really enjoyed this design, by far the best I've seen in a platform like this.

    Cheers!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Ok, I'm not getting it, here's my code:

    def solution(value)
    @new_value = "%05d" % (value)
    print "Value is #{@new_value}"
    end

    What is wrong? It results Exactly "Value is "5 digit formatted value""