Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* 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
You can’t perform that action at this time.