...

/

Solution Review: Create Phone Number

Solution Review: Create Phone Number

This lesson will explain the solution to the problem in the previous lesson.

There are various ways to solve the problem in the previous lesson. However, the question required the use of slice to solve the problem. Let’s discuss the solution now.

Solution #

Press + to interact
function createPhoneNumber(arr) {
return `(${arr.slice(0, 3).join('')}) ${arr.slice(3, 6).join('')}-${arr.slice(6).join('')}`;
}
console.log(createPhoneNumber([1,2,3,4,5,6,7,8,9,0]))
console.log(createPhoneNumber([3,5,7,1,2,0,9,8,6,4]))

Explanation #

This is an obvious solution. To take out the values ...

Access this course and 1400+ top-rated courses and projects.