1
def pad(array, min_size, value = nil)
  val_num = array.length - min_size.to_i
  if val_num >= 1
    p array.push(value*val_num.to_i)
  else
    p array
  end
end

p pad([1,2,3],5, "apple")

I'm trying to figure out why this code wont push the value into a new array, to pad the array. I've been working on this code for a few days, and everytime I try to implement it, it either only runs the original array, or it gives me nil. Is there anything obvious I miss?

2
  • 1
    I'm sure you can solve it. Hint: print val_num and see. Commented Nov 27, 2015 at 10:11
  • Please Have a look at this: stackoverflow.com/questions/25144971/… Commented Nov 27, 2015 at 10:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.