min, index], current) => {
const m = current > min ? min : current;
const r = current - m;
return [result > r ? result : r, m];
}
,[0, arr[0]])[0]
VS
const input = [...];
let isBought = false;
let income = 0; let current = 0;
for (let i = 0; i < input.length - 1; i++) {
if (!isBought && input[i] < input[i + 1]) {
current = input[i];
isBought = true;
} else if (isBought && input[i] > input[i +1]) {
income += input[i] - current;
isBought = false;
}
}
if (isBought) {
income += input[input.length - 1] - current;
}
А говнокод сверху или снизу?
Обсуждают сегодня