Create Phone Number
JavaScript
function createPhoneNumber(numbers) {
return `(${numbers.getRangeAsString(0,2)}) ${numbers.getRangeAsString(3,5)}-${numbers.getRangeAsString(6,9)}`;
}
Array.prototype.getRangeAsString = function(start, stop) {
var target = this, string = "";
for (let index = start; index <= stop; index++) {
string += target[index];
}
return string;
};
PHP
function createPhoneNumber($numbersArray) {
$numbers = implode("", $numbersArray);
return "(" . substr($numbers,0,3) . ") " . substr($numbers,3,3) . "-" . substr($numbers,6,4);
}
- javascript (Private)
- php (Private)
- 6-kyu (Private)
- codewars (Private)
- answer (Private)