I became a little more acquainted with using the "each" method. I was stumbling over this one in my own self-study before, but now I've got the hang of it.
It runs through each and every element in the array, but the absolute value signs give me some freedom to work with each element it cycles through. Unfortunately, it doesn't natively have anyway of keeping track of which index you're on.
I also learned from other people's solutions that I've been programming things the hard way, writing out copies of arrays and extra variables, unnecessarily.
There are so many simpler ways of doing things, like just sticking everything on the same line as "return", or finding the method for the array that does exactly what I want. I'm reinventing the wheel.
array.min will give you the minimum value stored wherever in your array. No need to rearrange it yourself and try to analyze it. Ruby's got a method for that already.
No comments:
Post a Comment