3 ms·
Because you're saving the O(N) time copy... iirc, Ruby's array doesn't expose the distinction between length and capacity, but internally it may decide to amor
by brandonbloom 10y ago
Because you're saving the O(N) time copy...
iirc, Ruby's array doesn't expose the distinction between length and capacity, but internally it may decide to amortize the cost of such copies. For example, if reject only removes a small % of elements, it may choose not to shrink capacity.
- leereeves 10y agoYou're not saving the O(N) time copy, just replacing it with an O(N) slide. (That's assuming you copy at all, instead of simply updating the reference.)
- brandonbloom 10y agoI meant O(N) space, as you said "That would still require O(n) space" - but a slide does not require additional space.