-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextToNum.js
30 lines (29 loc) · 837 Bytes
/
textToNum.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function textToNum(phone) {
function textToNum(phone) {
let phones = phone.split('');
let arr = [[], [], ['ABC'], ['DEF'], ['GHI'], ['JKL'], ['MNO'], ['PQRS'], ['TUV'], ['WXYZ']];
let newArr = '';
for (let i = 0; i <= phones.length - 1; i++) {
let num = arr.findIndex((a) => a.join('').split('').includes(phones[i]));
if (num < 0) {
newArr += phones[i];
} else {
newArr += num;
}
}
return newArr;
}
let phones = phone.split('');
let arr = [[], [], ['ABC'], ['DEF'], ['GHI'], ['JKL'], ['MNO'], ['PQRS'], ['TUV'], ['WXYZ']];
let newArr = '';
for (let i = 0; i <= phones.length - 1; i++) {
let num = arr.findIndex((a) => a.join('').split('').includes(phones[i]));
if (num < 0) {
newArr += phones[i];
} else {
newArr += num;
}
}
return newArr;
}
console.log(textToNum('123-647-EYES'));