diff --git a/solutions/typescript/line-up/1/line-up.ts b/solutions/typescript/line-up/1/line-up.ts new file mode 100644 index 0000000..23ae42e --- /dev/null +++ b/solutions/typescript/line-up/1/line-up.ts @@ -0,0 +1,16 @@ +export function format(name: string, number: number): string { + let ending = "th"; + let numberStr = String(number); + const modOne = number % 10 === 1; + const modTwo = number % 10 === 2; + const modThree = number % 10 === 3; + if ( + (modOne || modTwo || modThree) && + numberStr[numberStr.length - 2] !== "1" + ) { + if (modOne) ending = "st"; + else if (modTwo) ending = "nd"; + else ending = "rd"; + } + return `${name}, you are the ${number}${ending} customer we serve today. Thank you!`; +}