Day 25. Pre-course. Code Wars
Finally! After 24 days of doing the pre-course work, I now have a completely free day to spend doing code wars challenges. It means I can now focus the training on the aspects of Ruby I want to focus on (though at this stage, it could be argued this is the WHOLE of Ruby :-)). I have the entire day in front of me, and will aim to boost my current score of 79 to over 100. I would like to focus on the fundamentals, but perhaps will through in a level 7 or 6 challenge just to push me throughout the day. Look, I even have a leader position now! 21,060!
One of my aims is to refactor where possible, and this means using ternary operators. I impressed myself with this simple one. I had to find the middle characters / middle character of a string (depending on whether it was odd or even) and started out with this code:
def get_middle(s)
s.length.odd? ? s[s.length / 2] : s[s.length / 2–1] + s[s.length / 2]
end
refactored it to this:
def get_middle(s)
s.length.odd? ? s[s.length / 2] : s[s.length / 2–1] + s[s.length / 2]
end
Well, I was impressed anyway. Score now 81, leaderboard 20, 542! lol.
In another turn of events, I needed assistance on stackoverflow in answering a question about adding the results of an array iteration together. Normally, I receive abusive replies and get marked down, but I think in this instance, success — I got the answer I was looking for, received no abusive comments, and now understand the .inject method more! Here is the link: http://stackoverflow.com/questions/37324452/how-to-add-the-results-of-iterating-over-an-array