-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge_04.js
36 lines (32 loc) · 962 Bytes
/
challenge_04.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
34
35
36
import { DATA_CHALLENGE_04 } from './consts.js'
const filesArray = DATA_CHALLENGE_04.split('\n')
const realFiles = []
filesArray.map((file) => {
const fileContent = file.split('-')
const fileString = fileContent[0]
const checksum = fileContent[1]
const fileStringArray = fileString.split('')
const checksumArray = checksum.split('')
const result = []
checksumArray.map((letter, i) => {
if (fileStringArray.includes(letter)) {
if (i < checksumArray.length - 1) {
if (
fileStringArray.indexOf(letter) <
fileStringArray.indexOf(checksumArray[i + 1])
) {
result.push(true)
}
} else {
if (
fileStringArray.indexOf(letter) >
fileStringArray.indexOf(checksumArray[i - 1])
) {
result.push(true)
}
}
}
})
if (result.every((e) => e === true)) realFiles.push(fileContent)
})
console.log(filesArray[32].split('-')[1])