-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (32 loc) · 810 Bytes
/
index.js
File metadata and controls
38 lines (32 loc) · 810 Bytes
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
const fs = require('fs')
const data = fs.readFileSync('colors.txt', 'utf-8')
const array = JSON.parse(data)
function countColors(array) {
let count = 0,
maxLine = 0,
betPos = '',
aftPos = '',
colFin = ''
for (let idx = 0; idx < array.length; idx += 2) {
if (
(
(betPos === array[idx]) || (aftPos === array[idx + 1])
) && (
array[idx - 1] !== array[idx]
)
) {
count += 2
} else {
count = 2
betPos = array[idx]
aftPos = array[idx + 1]
}
if (count > maxLine) {
maxLine = count
colFin = array[idx]
}
}
return ({ total: maxLine, color: colFin })
}
const { total, color } = countColors(array)
console.log(`submit ${total}@${color}`)