Skip to content
Snippets Groups Projects
Commit 9d3c3324 authored by Sofiya Tepikin's avatar Sofiya Tepikin
Browse files

Fix getOrdinalSuffix and add a formatting function

parent e5418c32
No related branches found
No related tags found
No related merge requests found
......@@ -64,14 +64,24 @@ export function getBleedingPredictionRange(prediction) {
}
export function getOrdinalSuffix(num) {
const suffixes = {
1: 'st',
2: 'nd',
3: 'rd',
default: 'th'
const j = num % 10
const k = num % 100
if (j === 1 && k !== 11) {
return 'st'
}
if (j === 2 && k !== 12) {
return 'nd'
}
if (j === 3 && k !== 13) {
return 'rd'
}
const numAsString = num.toString()
const lastNumber = numAsString[numAsString.length - 1]
return suffixes[lastNumber] || suffixes.default
}
\ No newline at end of file
return 'th'
}
export function formatWithOrdinalSuffix(num) {
return num + getOrdinalSuffix(num)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment