-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathbeer-song.example.ts
40 lines (35 loc) · 1.02 KB
/
beer-song.example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Beer {
private static pluralize(input: number): string {
if (input === 0) {
return "o more bottles "
}
return (input === 1) ? "1 bottle " : `${input} bottles `
}
public static verse(input: number): string {
const wall = "of beer on the wall"
if (input === 0) {
return `N${Beer.pluralize(0)}${wall}, n${Beer.pluralize(0)}of beer.
Go to the store and buy some more, ${Beer.pluralize(99)}${wall}.
`
}
if (input === 1) {
return `${Beer.pluralize(1)}${wall}, ${Beer.pluralize(1)}of beer.
Take it down and pass it around, n${Beer.pluralize(0)}${wall}.
`
}
return `${Beer.pluralize(input)}${wall}, ${Beer.pluralize(input)}of beer.
Take one down and pass it around, ${Beer.pluralize(input - 1)}${wall}.
`
}
public static sing(end: number = 99, start: number = 0): string {
let temp = ``
for (let i: number = end; i >= start ; i -= 1) {
temp += Beer.verse(i)
if (i !== start ) {
temp += "\n"
}
}
return temp
}
}
export default Beer