20 lines
398 B
JavaScript
20 lines
398 B
JavaScript
|
const { Glib } = require('../../lib');
|
||
|
|
||
|
const VALUE = {
|
||
|
'(': 1n,
|
||
|
')': -1n,
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
'1': (input) =>
|
||
|
Glib.fromIterable(input)
|
||
|
.map((char) => VALUE[char] || 0n)
|
||
|
.sum(),
|
||
|
'2': (input) =>
|
||
|
Glib.fromIterable(input).partialReduce(
|
||
|
([floor], char, index) => [floor + (VALUE[char] || 0n), index + 1],
|
||
|
([floor]) => floor >= 0,
|
||
|
[0n, 0],
|
||
|
)[1],
|
||
|
};
|