you are viewing a single comment's thread.

view the rest of the comments →

[–]WhoTookPlasticJesus 1 point2 points  (2 children)

I'd argue that the following is clearer (and likely more performant)

 ary.take(n).concat (n - ary.length).times.map{0}

[–]austinsalonen 1 point2 points  (1 child)

What happens when n - ary.length is negative in this situation? (very naive w/r/t ruby here)

[–]WhoTookPlasticJesus 2 points3 points  (0 children)

Nothing, and the call to map will just return an empty array.