deno.land / x / masx200_leetcode_test@10.6.5 / reformat-phone-number / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export default function reformatNumber(number: string): string { //@ts-ignore const str = number.replaceAll(/\-|\s/g, ""); const arr = Array(Math.ceil(str.length / 3)).fill(0).map((_, i) => str.slice(i * 3, i * 3 + 3) );
if (arr[arr.length - 1].length === 1) { arr[arr.length - 1] = arr[arr.length - 2].slice(-1) + arr[arr.length - 1]; arr[arr.length - 2] = arr[arr.length - 2].slice(0, 2); } // console.log(arr) return arr.join("-");}
masx200_leetcode_test

Version Info

Tagged at
a year ago