-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmauriceWins.js
33 lines (30 loc) · 1.32 KB
/
mauriceWins.js
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
// Steve and Maurice have racing snails. They each have 3, a slow (s), medium (m) and fast (f) one.
// Although Steve's snails are all a bit stronger than Maurice's, Maurice has a trick up his sleeve. His plan is:
// Round 1: [s, f] Sacrifice his slowest snail against Steve's fastest.
// Round 2: [m, s] Use his middle snail against Steve's slowest.
// Round 3: [f, m] Use his fastest snail against Steve's middle.
// Create a function that determines whether Maurice's plan will work by outputting true if Maurice wins 2/3 games.
// The function inputs:
// Array 1: [s, m, f] for Maurice.
// Array 2: [s, m, f] for Steve.
// Examples:
// mauriceWins([3, 5, 10], [4, 7, 11]) ➞ true
// Since the matches are (3, 11), (5, 4) and (10, 7), Maurice wins 2 out of 3.
// mauriceWins([6, 8, 9], [7, 12, 14]) ➞ false
// Since the matches are (6, 14), (8, 7) and (9, 12), Steve wins 2 out of 3.
// mauriceWins([1, 8, 20], [2, 9, 100]) ➞ true
// Notes:
// Maurice wins if his competing snail's speed strictly exceeds Steve's competing snail's speed.
// Steve will always play in this order: [f, s, m].
function mauriceWins(mSnails, sSnails) {
if (
mSnails[0] < sSnails[2] &&
mSnails[1] > sSnails[0] &&
mSnails[2] > sSnails[1]
) {
return true;
} else {
return false;
}
}
console.log(mauriceWins([3, 5, 10], [4, 7, 11]));