> For the complete documentation index, see [llms.txt](https://davin-hong3.gitbook.io/d/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davin-hong3.gitbook.io/d/programming/hackerrank/hackerrank-10-days-javascript-challenge/day-5-arrow-functions.md).

# Day 5 : Arrow Functions

**Objective**

In this challenge, we practice using *arrow functions*. Check the attached tutorial for more details.

**Task**

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:

* If the element is even, multiply the element by 2.
* If the element is odd, multiply the element by 3.

The function must then return the modified array.

![](https://2068334946-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fow1iM27u7disHeJiSlBC%2Fuploads%2FWcLAYWhCAgMdlW4v0tVH%2Fimage.png?alt=media\&token=523b1abf-f7b8-4e66-b7e5-4ca3110135d9)

```javascript
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();    
});

function readLine() {
    return inputString[currentLine++];
}

// Modify and return the array so that all even elements are doubled and all odd elements are tripled.
// MAIN Function
function modifyArray(nums) {
    let result = [];
    for (let i =0; i < nums.length; i ++){
        if (nums[i] % 2 == 0 ){
            result.push(2 * nums[i]);
        } else {
            result.push(3* nums[i])
    } 
    }
    return result;
} 
function main() {
    const n = +(readLine());
    const a = readLine().split(' ').map(Number);
    
    console.log(modifyArray(a).toString().split(',').join(' '));
}
```
