util conf

pull/29/head
Matthew 2020-10-06 15:06:17 -04:00
parent 036355dce6
commit 1bad2f8f39
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 19 additions and 0 deletions

View File

@ -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`;
}
}