DEV Community

Cover image for Triple All the Numbers
Jackson Reeves
Jackson Reeves

Posted on

Triple All the Numbers

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
}
view raw tripler.js hosted with ❤ by GitHub

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs