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.
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)