Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function equalPairs(input) {
- let num = Number(input[0]);
- let value = Number(input[1]) + Number(input[2]);
- let maxdiff = 0;
- for (let i = 3; i < num * 2; i++){
- let current = Number(input[i++]) + Number(input[i]);
- let diff = Math.abs(value - current);
- if (diff > maxdiff){
- maxdiff = diff;
- } else{
- value = current;
- }
- }
- if (maxdiff === 0){
- console.log(`Yes, value=${value}`);
- } else{
- console.log(`No, maxdiff=${maxdiff}`);
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function equalPairs(input) {
- let num = Number(input[0]);
- let value = Number(input[1]) + Number(input[2]);
- let maxdiff = 0;
- for (let i = 3; i < num * 2; i++){
- let current = Number(input[i++]) + Number(input[i]);
- let diff = Math.abs(value - current);
- diff > maxdiff ? maxdiff = diff : value = current;
- }
- console.log(maxdiff === 0 ? `Yes, value=${value}` : `No, maxdiff=${maxdiff}`);
- }
Add Comment
Please, Sign In to add comment