-
Notifications
You must be signed in to change notification settings - Fork 0
/
wellOfIdeas.ts
25 lines (21 loc) · 906 Bytes
/
wellOfIdeas.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
// Codewars - Andreas Sosilo
// 8 kyu - TypeScript - Well of Ideas - Easy Version
/*
Task:
-----
For every good kata idea there seem to be quite a few bad ones!
In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, return 'Fail!'.
*/
export function well(x: string[]): string {
let goodCtr: number = 0;
x.forEach((el, i) => {
el === 'good' && goodCtr++;
});
return goodCtr ? (goodCtr > 2 ? 'I smell a series!' : 'Publish!') : 'Fail!';
}
// TEST CASES
console.log(well(['bad', 'bad', 'bad'])); // 'Fail!'
console.log(well(['good', 'bad', 'bad', 'bad', 'bad'])); // 'Publish!'
console.log(
well(['good', 'bad', 'bad', 'bad', 'bad', 'good', 'bad', 'bad', 'good'])
); // 'I smell a series!'