I want to transform [1, 2, 3] into ['123']. I need to convert [1, 2, 3] to ['123'] using an arrow function only (no regex):
Required steps:
const functionOne = (arrayOne) => {
};
console.log(functionOne([1, 2, 3]));
This is my attempt:
Firstly, I converted the array to a string which resulted in 1,2,3
Next, I removed the commas in order to combine the numbers. This yielded 123.
Finally, I tried to place the number as a string back into the array but this did not work as expected. It gave me ['1', '2', '3']
instead of ['123']
. I believe the issue lies with the .split
method in my code and I am currently exploring other options as I learn JavaScript.
const functionOne = (arrayOne) => {
let stepOne = arrayOne.toString(arrayOne => arrayOne.toString());
console.log(stepOne);
stepOne = stepOne.split(',').join('');
console.log(stepOne);
return stepOne.split('');
};
console.log(functionOne([1, 2, 3]));