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
function verses(bottles) { | |
const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`; | |
return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => [ | |
`${count(b, true)} of beer on the wall, ${count(b)} of beer.`, | |
b > 0 | |
? `Take one down and pass it around, ${count(b - 1)} of beer on the wall.` | |
: `Go to the store and buy some more, ${count(bottles)} of beer on the wall.` | |
]); | |
} |
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 const repeat = (str, num) => `${Array(num + 1)}`.replaceAll(/,/g, str); | |
export const kebabCase = (string, delimiter = " ") => | |
string | |
.split(delimiter) | |
.map((word) => [ | |
`${Number.NEGATIVE_INFINITY}`.slice(0, 1)[0], | |
word.toLowerCase(), | |
]) | |
.flat() |
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 default const splitn = (s, d, n = Infinity) => { | |
const a = s.split(d); | |
return [ | |
...a.slice(0, n - 1), | |
...(a.length >= n ? [a.slice(n - 1).join(d)] : []) | |
]; | |
}; |
OlderNewer