Created
July 3, 2017 19:36
-
-
Save a-eid/a36f8eb70f8046622f893e19a75548f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* takes single number and convert it to a position | |
@arg: | |
Int: number | |
@returns: | |
String: position (ie: 1st , 2nd , 3rd , 4th ,... 101st , 1004th ...) | |
*/ | |
var calcPosition = (rank) => { | |
let final | |
let length = rank.toString().length | |
--length | |
if (length >= 1) { | |
let z = "0" | |
for (i = 1; i < length; i++) | |
z += "0" | |
let d = "1" + z | |
console.log("d " , d ) | |
final = rank % parseInt(d) | |
} else { | |
final = rank | |
} | |
switch (final) { | |
case 1: | |
rank = rank + "st"; break | |
case 2: | |
rank = rank + "nd"; break | |
case 3: | |
rank = rank + "rd"; break | |
default: | |
rank = rank + "th"; | |
} | |
return rank | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment