Last active
April 22, 2020 19:12
-
-
Save qubbit/71b73373f15b34f76df6293a48536a0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function interlace(array: any[], joiner: any): any[] { | |
const result: any[] = []; | |
if (!array || !array.length) { | |
return result; | |
} | |
let i; | |
for (i = 0; i < array.length - 1; i++) { | |
result.push(array[i]); | |
result.push(joiner); | |
} | |
result.push(array[i]); | |
return result; | |
} | |
export function ander(strings: string[]): string { | |
if (!strings || !strings.length) { | |
return ''; | |
} | |
if (strings.length === 1) { | |
return strings[0]; | |
} | |
if (strings.length === 2) { | |
return `${strings[0]} and ${strings[1]}`; | |
} | |
strings[strings.length - 1] = `and ${strings[strings.length - 1]}`; | |
return strings.join(', '); | |
} | |
export function sentenceCase(paragraph: string) { | |
if (!paragraph) { | |
return; | |
} | |
return paragraph | |
.split('. ') | |
.map(sentence => `${sentence[0].toUpperCase()}${sentence.substring(1)}`) | |
.join('. '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment