Reading documentation can be really intimidating as a coding noob. I’ve put together a few tips on how to make deciphering docs a little easier!
I clicked on the first link and it doesn’t look like my problem at all. I don’t know what an object is yet, so I don’t think this is the right article. Plus I know that the map I want has a dot before it. I think I might add more keywords to narrow down my search. Reading over my problem again, it looks like I am mapping over an array. So I’ll add array into my search.
Ok, even more articles. But these look more promising! Reading the description on the second one, it looks like map is a method that creates a new array populated with the results of calling a provided function on every element in the calling array. I know from my problem that I’m expected to return a new array. I’ll click on this article and find out more
Right away, I see an array of numbers! This is looking pretty similar to my problem. I’m going to scroll down to the description section to get a better glimpse of what I’m reading about
Hmmm, I don’t know what a callback function is but I remember seeing it by the syntax section of this article
Ok so a callback is a function that is called for every element of the array. Each time the callback (which we now know is a function) executes, the returned value is added to newArray.
So in my example, each element in the array is a number. Each time the function runs, something is going to happen to each number.
Now lets go back to the description of map:
map calls a provided
callback function once for each element in an array, in order, and constructs a new array from the results.
callback is invoked only for indexes of the array which have assigned values (including
This is a lot of text so I’m going to break up each piece to be a bullet point and swap out some words for less complicated synonyms to make the whole thing easier to read
- Map calls a callback function once for each element in an array
- This happens in order
- A new array is made from the results
- The function is run only for indexes of the array which have assigned values
- Undefined can be an array value
This is already making way more sense. Basically a map is going to go through each element in an array, do something to it, and return each modified value in an array (with the same number of elements as the original). It sounds just like the problem I have been working on!
By using keywords from the problem you are working on to search and breaking things down in the article to small digestible pieces, navigating and reading docs can feel less intimidating. I hope this is useful information for those of you who have just started your coding journey!