2019-03-01 Daily Challenge

What I've done today is Create Phone Number in JavaScript.

Problem

Create Phone Number

Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.

Example:

1
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) 

The returned format must be correct in order to complete this challenge.
Don't forget the space after the closing parentheses!

Solution

1
2
3
4
5
6
7
function (numbers){
return `(${numbers.slice(0, 3).toString().replace(/,/gi, '')}) ${numbers.slice(3, 6).toString().replace(/,/gi, '')}-${numbers.slice(6, 10).toString().replace(/,/gi, '')}`;
}

function createPhoneNumber(numbers){
return numbers.join('').replace(/(...)(...)(.*)/, '($1) $2-$3');
}

Original: Big Box  2019-03-01 Daily Challenge


Guess you like

Origin www.cnblogs.com/chinatrump/p/11423799.html