function solve ({ A, K }) {
if (K === 0) return A.reduce((a, b) => a + b, 0);
A.sort((a,b) => b - a)
for (i =0; K > 0; i++, K--) {
if (A[i] > 0) {
A[i] = -A[i]
} else {
break
}
}
A.sort((a,b) => b - a)
if (K%2 === 1) {
A[0] = -A[0]
}
return A.reduce((a, b) => a + b, 0)
}
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin
})
const lines = []
let counter = 0
let maxcounter = 0
rl.on('line', (line) => {
lines.push(line)
}).on('close', () => {
for (let i = 1; i < lines.length; i++) {
if (/^[1]+$/.test(lines[i])) {
counter = lines[i].length + counter
} else {
if (maxcounter < counter) {
maxcounter = counter
}
counter = 0
}
}
if (maxcounter < counter) {
maxcounter = counter
}
process.stdout.write(maxcounter.toString())
})
const mainDiv = document.getElementsByTagName('div')
let lastDiv
const finLastDiv = (el) => {
if(el.children[el.children.length - 1]) {
finLastDiv(el.children[el.children.length - 1])
}
else {
lastDiv = el
}
}
finLastDiv(mainDiv[0])
console.log(lastDiv)
console.log(lastDiv.innerHTML) // => 2
function promisify (api) {
const promisedApi = {}
for (const prop in api) {
if (typeof (api[prop]) === 'function') {
let loadScriptPromise = function (src) {
return new Promise((resolve, reject) => {
api[prop]((err, script) => {
if (err) reject(err)
else resolve(script);
}, src);
})
}
promisedApi[prop] = loadScriptPromise
} else if (Object.keys(api[prop]).length > 0) {
promisedApi[prop] = promisify(api[prop])
} else {
promisedApi[prop] = api[prop]
}
}
return promisedApi
};
class Journal {
constructor(date) {
this.date = date;
}
formatDate(date) {
return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
}
get title() {
return `Выпуск от ${this.formatDate(this.date)}`;
}
}
Journal.compare = (journalA, journalB) => journalA.date - journalB.date;
Journal.min = (journals) => {
let min = 0;
for (let i = 0; i < journals.length; i++) {
if (Journal.compare(journals[min], journals[i]) > 0) min = i;
}
return journals[min];
};
const journals = [
new Journal(new Date(2012, 1, 1)),
new Journal(new Date(2012, 0, 1)),
new Journal(new Date(2011, 11, 1)),
];
const minJournal = Journal.min(journals);
const { title } = minJournal;