In this HackerRank Day 5: Arrow Functions 10 days of javascript problem solution Complete the function in the editor. It has one parameter: an array, nums. It must iterate through the array performing one of the following actions on each element:
  1. If the element is even, multiply the element by 2.
  2. If the element is odd, multiply the element by 3.
The function must then return the modified array.


HackerRank Day 5: Arrow Functions problem solution


Problem solution in JavaScript programming.

/*
 * Modify and return the array so that all even elements are doubled and all odd elements are tripled.
 * 
 * Parameter(s):
 * nums: An array of numbers.
 */
function modifyArray(nums) {
    return nums.map(function(v) {
        return v * ((v % 2 == 0) ? 2 : 3);
    });
}