I was blocked on a simple things as missing semicolon in the code many times. We’re humans and it is quite easy to omit small things, as for example missing symbol, wrong syntax, or a typo. To solve a problem, I usually check the code couple of times and use chrome debugger. If the problem still exists and I am sure that I run out of ideas, then I ask someone for the code review. However, before that I explain what I did to the "reviewer" and sometimes, it is just enough to find the problem by my own!
Small errors are easy to make and often hard to find.
I recently had a larger problem connected with incorrect usage of one of the loops in a program. At first, I did not see the error and got frustrated since the code should work, but it didn't. Since begging the code to work did not give much chance for the success, I started with reviewing the code line by line. I also used chrome debugger. Summing up, I tried to question my assumptions, find patterns and anything that may interrupt them, looked for things that seem to be odd, missing, or shouldn't be in the code. I also tried not to do any unnecessary code re-factorig at the time.
Currently, I'm discovering some techniques, and some are already known from my previous experience - just as googling, reading error messages, or consulting. When coding, I find the first two very helpful.
Googling is usually a quick way to find resources or someone else who already has had a similar problem. Reading error messages, no matter whether they come from git or debugger, is a useful habit. It is surprising how many people do not read them. Writing a pseudocode seems useful especially when solving some more complex problem, it helps to simplify it.
map() takes an array and a function and returns a new one where each element of the new array is a result of applying the function to each element of the original array
var englishWords = ['dog', 'flower', 'home', 'eight']; function italianize(i) { return i + "o"; } var italian_words = englishWords.map(italianize); console.log(italian_words);
filter() takes an array and a function and returns a new array which contains only those elements from the original array for which the function returns true
var dirtyWords = ['flip', 'moon', 'flop', 'sun'];
function filterSwearWords(word) {
return !word.includes("f");
}
reduce()'reduces' an array by applying the given function to each array element, reduce() will return the accumulated value
var myWords = ['Lazy', 'dog', 'sleeps', 'whole', 'day'];
function makePoem(poemSoFar, newWord) {
return poemSoFar + " " + newWord;
}
var myPoem = myWords.reduce(makePoem, "My beautiful poem:");
console.log(myPoem);