-
Notifications
You must be signed in to change notification settings - Fork 0
/
getScore.js
32 lines (27 loc) · 814 Bytes
/
getScore.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
module.exports = function(colors) {
let colorArray = ["white","blue","black","red","green"];
let score = 0;
let indexOfA = colorArray.indexOf(colors[0].toLowerCase());
if (indexOfA > 0) {
for (let i = 0; i < indexOfA; i++) {
colorArray.push(colorArray.shift());
score++;
}
}
score += colors.reduce((total, color) => {
let thisIndex = colorArray.indexOf(color.toLowerCase());
let timesShifted = 0;
if (thisIndex > 0) {
for (var j = 0; j < thisIndex; j++) {
colorArray.push(colorArray.shift());
timesShifted++;
total++;
}
}
if (timesShifted > 1) {
total += 5;
}
return total;
}, 0);
return score;
}