-
Notifications
You must be signed in to change notification settings - Fork 0
/
숫자놀이.js
32 lines (29 loc) · 939 Bytes
/
숫자놀이.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
31
32
const numArr = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
let m = 8;
let n = 28;
const numRangeArr = [];
const numList = [];
for (let i = m; i <= n; i++) {
numRangeArr.push(i.toString());
}
for (let i = 0; i < numRangeArr.length; i++) {
if (numRangeArr[i].length === 1) {
const letNum1 = numArr[parseInt(numRangeArr[i][numRangeArr[i].length - 1])];
numList.push({
originNum: parseInt(numRangeArr[i]),
letterNum: letNum1
})
}
if (numRangeArr[i].length === 2) {
const letNum2 = numArr[parseInt(numRangeArr[i][numRangeArr[i].length - 2])].toString() +' '+ numArr[parseInt(numRangeArr[i] [numRangeArr[i].length - 1])].toString();
numList.push({
originNum: parseInt(numRangeArr[i]),
letterNum: letNum2
})
}
}
numList.sort((a,b)=>{
if(a.letterNum < b.letterNum){
return -1;
}
}).forEach(item=>console.log(item.originNum));