3 ms·
Even in languages like C# the standard for-loop seems to be heading in the direction of being considered harmful. Its status hasn't gone nearly as far along th
by bunderbunder 14y ago
Even in languages like C# the standard for-loop seems to be heading in the direction of being considered harmful. Its status hasn't gone nearly as far along the path as for Ruby, but the tide's turning that way.
As far as creating a new array (or several new arrays) goes, there are some new considerations such as composability that are starting to be valued more highly than efficiency. And pure functions are more composable than ones that mutate the existing data.
Granted, the n < 0 case could still be handled in a way that's more efficient but still pure by allocating an array and filling it backward rather than using two reverses and an iterator.