Ad
  • Default User Avatar

    if w != (vmax && vmin)
    compares w to a boolean value of vmax && vmin, and because w, vmax and vmin are all numbers it naturally doesn't work.

  • Custom User Avatar

    first, this is NOT an issue. It's just a question.
    for your question, my answer is: perhaps you should not using delete in the map! loop. I guess it will skip some index(I'm not sure. because I don't know Ruby and I've not try your code)

  • Custom User Avatar

    delete mutates the original array, and in general putting side effect code inside a pure list method (map) is never a good idea.

  • Default User Avatar

    After each deletion the elements after the deleted one are shifted and the indices get offset too. It's not a kata issue. BTW, modifying input in-place is usually not expected unless explicitly asked for.

  • Default User Avatar

    Oops, you put a double equals instead of a single equals. Change counter == counter + 1 to counter = counter + 1

  • Custom User Avatar

    Actually, your code is wrong. You need to change your break statement to counter == n+1 or need to put your counter increment after your break statement.

    Your counter variable exceeds the value of n. This is the reason why it takes so long, it's because you end up with an infinite loop, since it never reaches the break statement.

    Example

    power_of_two(0)
    
    loop do                  #first loop
      counter = 0 + 1
      
      break if 1 == 0
    end