This function takes in an array and returns a new array containing each element from the first array after they were multiplied by three. Note the comments interspersed in the code. They act as guideposts, explaining each step of the code in pseudocode to make it easier for the non-coder to understand.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tripler(array) { | |
// Confirm in the function | |
console.log('Inside the tripler() function:'); | |
// Take in an array, and return a new array | |
const result = []; | |
// Iterate through array passed in | |
for (let i = 0; i < array.length; i++) { | |
let num = array[i]; | |
// Multiply each element by 3 | |
let multiple = num * 3; | |
// Push that element into my result. | |
result.push(multiple); | |
} | |
// Return result | |
return result | |
} |
Top comments (0)