Create Copy Of The Given Array (myArray) Using Spread Operator

Create Copy Of The Given Array (myArray) Using Spread Operator

Input

This input will a single containing an array

Output

The output should be a single line containing an array with the values of myArray

Sample Input

[ ‘x’ , ‘y’, ‘z’]

Sample Output

[ ‘x’, ‘y’, ‘z’ ]

Code

"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((str) => str.trim());

  main();
});

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

function main() {
  let myArray = JSON.parse(readLine().replace(/'/g, '"'));
/* Please do not modify anything above this line */

  let newArray = [...myArray]// Write your code here.
  
/* Please do not modify anything below this line */  
  console.log(newArray);
}

Leave a Comment