Our task: add 5 to each item in an array.
//iterate through the array
for (var i = 0; i < arr.length; i++) {
//add 5 to each item
arr[i] += 5;
}
Pseudocode:
//iterate through the array
Pseudocode:
//iterate through the array
//add 5 to each item
Actual code:
You'll notice that each line of pseudocode gives us clear instructions for a task we can do
All the time.
It's super valuable.
create a function that multiplies every even number in an input array by 10 and returns the modified array
//declare a function that takes an array as a parameter
//iterate through that array
//check to see if each item is even
//if so, overwrite the array at that position with that item multiplied by 10
//return the array
"invoke" this with the array [1,2,3,4]
(all in your head, or before coding)
This helps you spot bugs before you even write code!
These exercises are not necessarily tied to today's lecture material (though you should always use pseudocoding to solve problems!)
Practice going through your previous repos/assessments (especially ones you found difficult) and try pseudocoding your way through them.