From 1bad2f8f395e1a2e99ad85b09e048fbd99ddf040 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Tue, 6 Oct 2020 15:06:17 -0400 Subject: [PATCH] util conf --- src/class/Util.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/class/Util.ts b/src/class/Util.ts index aa5432a..7512762 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -169,4 +169,23 @@ export default class Util { } return string; } + + public percentile(arr: number[], val: number) { + return (100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0)) / arr.length; + } + + public ordinal(i: number) { + const j = i % 10; + const k = i % 100; + if (j === 1 && k !== 11) { + return `${i}st`; + } + if (j === 2 && k !== 12) { + return `${i}nd`; + } + if (j === 3 && k !== 13) { + return `${i}rd`; + } + return `${i}th`; + } }