I am a student studying JavaScript. It hasn't been long since I studied. Example, createPhoneNumber The length is up to 11 digits. I wrote the code in question like this.
function createPhoneNumber(arr) {
let first = '(010)';
if(arr.length === 11){
return `(${arr.slice(0,3).join('')})${arr.slice(3,7).join('')}-${arr.slice(7,11).join('')}`;
}
return `${first}${arr.slice(0,4).join('')}-${arr.slice(4,8).join('')}`;
}
I think it's very messy code.
Is it better to add a new variable to make it shorter and simpler?