Below is a function for joining words. Given the first or last word could be a string like 7 1/2, how would I ensure that; if the word contains a fraction, format the fraction with (superscript) tags.. so it shows nicely like below?
export const joinWords = (words: string[]): string => {
if (words.length === 1) {
return words[0];
}
const firstWords = words.slice(0, words.length - 1);
const lastWord = words[words.length - 1];
const oxfordComma = words.length > 2;
//if firstWords or lastword contains "/"...Logic???
return firstWords.join(', ') + `${oxfordComma ? ', ' : ''} and ${lastWord}`;
};
I found an alternate way, where I use the replace method. I am using svelte hence the onmount..