Skip to content

Commit cb0db81

Browse files
authored
Create Holiday V - SeaSick Snorkelling.js
1 parent b931a37 commit cb0db81

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Holiday V - SeaSick Snorkelling.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Description:
3+
Thanks to the effects of El Nino this year my holiday snorkelling trip was akin to being in a washing machine... Not fun at all.
4+
5+
Given a string made up of '~' and '_' representing waves and calm respectively, your job is to check whether a person would become seasick.
6+
7+
Remember, only the process of change from wave to calm (and vice versa) will add to the effect (really wave peak to trough but this will do). Find out how many changes in level the string has and if that figure is more than 20% of the string, return "Throw Up", if less, return "No Problem".
8+
*/
9+
function seaSick(x){
10+
var count = 0;
11+
for (var i = 0; i < x.length - 1; i++) {
12+
if (x[i] !== x[i+1]) {
13+
count++;
14+
}
15+
}
16+
if (count / x.length > 0.2) {
17+
return "Throw Up";
18+
}
19+
return "No Problem";
20+
}

0 commit comments

Comments
 (0)