-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseNum.js
More file actions
38 lines (38 loc) · 931 Bytes
/
reverseNum.js
File metadata and controls
38 lines (38 loc) · 931 Bytes
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
33
34
35
36
37
38
/* finding out reverse of a number and naming it */
module.exports = function revNum(a){
/* convert to string , split & reverese to access the element and rename it */
var val = [];
var str = "";
var i;
a = a.toString();
a = a.split("");
a = a.reverse();
/* find out the string matching to the number */
for (i = 0; i < a.length; i++) {
if(a[i] === "1")
val[i] = "ONE";
else if(a[i] === "2")
val[i] ="TWO";
else if(a[i] === "3")
val[i] = "THREE";
else if(a[i] === "4")
val[i] = "FOUR";
else if(a[i] === "5")
val[i] = "FIVE";
else if(a[i] === "6")
val[i] = "SIX";
else if(a[i] === "7")
val[i] = "SIX";
else if(a[i] === "8")
val[i] = "EIGHT";
else if(a[i] === "9")
val[i] = "NINE";
else if(a[i] === "0")
val[i] = "ZERO";
}
/* convert it to string again */
for(i of val)
str = str + " " + i;
/* return the result */
return str;
}