-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (24 loc) · 807 Bytes
/
index.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
export const checkStepNumbers = (systemNames = [], stepNumbers = []) => {
const resArr = systemNames.reduce((acc, el, index) => {
return acc[el]
? { ...acc, [el]: [...acc[el], stepNumbers[index]] }
: { ...acc, [el]: [stepNumbers[index]] };
}, {});
return systemNames.every(el => {
const lightsArr = resArr[el];
return lightsArr.slice(1).every((val, i) => val > lightsArr[i]);
});
};
export const checkStepNumbersAlt = (systemNames, stepNumbers) => {
let hashMap = new Map();
return systemNames.every(
(name, i, flag, value) => (
(value = hashMap.get(name)),
(flag = !!(!value && hashMap.set(name, [stepNumbers[i]]))),
!flag &&
((flag = value.at(-1) < stepNumbers[i]), flag) &&
value.push(stepNumbers[i]),
flag
)
);
};