Yes, you actually have to practice

by sawadin

I once took a “total immersion” Farsi class in college. Our textbook was written what seemed to me to be backwards, with each chapter starting off with full texts in Farsi, then a little vocab (not enough to read the texts), and only a few scant grammar lessons in the back. We were supposed to just “figure it out” and learn by practicing. I am used to poring over robust explanations of grammar and syntax before I try to read in a new language, let alone try to form a sentence on my own. I need to know where a language is going before I start to see patterns. Needless to say, I found that class to be an exercise in futility and did not enroll in a second semester.
But while that textbook was a little extreme for my taste, I know that I have a tendency to to swing to the other extreme and get caught up with theory and neglect doing drills with practical examples. It took me a surprisingly long time (maybe year 3 of learning Chinese?) to realize that I had this habit, and it took me even longer to train myself to study more effectively. Theory is great. Memorization is awesome. But it all leaks out of your brain like water through a sieve if you don’t actually practice. Apparently this is intuitive for most people.
So anyway, this is an extremely long-winded way of explaining why I now do Coderbyte or other similar code exercises every day. I’m still shaky on fundamentals, and the dumb mistakes I make kind of amaze me. Obviously I make far fewer of them when I actually practice the easy stuff. I’m looking forward to eventually getting to the day when either all of this stuff is automatic or I am writing complex enough code on real projects that I actually have to incorporate many different methods and get practice that way.
In this particular problem, where the objective is to capitalize the first letter of each word, I forgot two important things that made the solution unnecessarily difficult:
function LetterCapitalize(str) {
  str = str.split(” “);
  for (var i = 0; i <str.length; i++) {
    str[i] = str[i].split(“”);
    str[i][0] = str[i][0].toUpperCase();
    str[i] = str[i].join(“”);
  str = str.join(” “);
  return str;
The first was that I couldn’t figure out how to make the changes I was making (str[i][0].toUpperCase()) during each iteration of the loop permanent. Make a second array and use push? Create more loops? More variables? I have no idea why at first I didn’t remember to just set str[i][0] equal to the desired value.
The second ridiculous problem I had was figuring out how to iterate over the individual letters in str[i]. I was really hung up on the idea of using a second for loop, and I couldn’t figure out why that wasn’t working. I forgot that str[i] was a string, not an array, and you can’t iterate over a string with a for loop. [ I also realized that no iteration was necessary anyway because I could use charAt or just position 0].