G2A Many GEOs
SHARE
TWEET

08. Equal Pairs

a guest Apr 10th, 2020 140 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function equalPairs (args) {
  2.     let number = Number (args[0]);
  3.     let sumOne = Number(args[1]) + Number(args[2]);
  4.     let sumTwo = sumOne;
  5.  
  6.     for (i = 3; i <= (2 * number); i += 2) {
  7.         if ((Number(args[i]) + Number(args[i+1])) != sumOne) {
  8.             let newSum = Number(args[i]) + Number(args[i+1]);
  9.             if (Math.abs (newSum - sumTwo) > Math.abs(sumTwo - sumOne)) {
  10.                 sumOne = Number(args[i-1]) + Number(args[i-2]);
  11.                 sumTwo = newSum;
  12.             }
  13.         }
  14.     }
  15.     if (sumOne == sumTwo) {
  16.         console.log (`Yes, value=${sumTwo}`);
  17.     } else {
  18.         console.log ('No, maxdiff=' + Math.abs (sumOne - sumTwo));
  19.     }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top