Aliendreamer

js equal numbers

Jun 9th, 2018
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function equalPairs (input) {
  2.   input = input.map(Number)
  3.   let count = input[0]
  4.   let first = input[1]
  5.   let second = input[2]
  6.   let total = first + second
  7.   let maxDifference = 0
  8.  
  9.   for (let i = 3; i <= count * 2; i += 2) {
  10.     first = input[i]
  11.     second = input[i + 1]
  12.  
  13.     let currentTotal = first + second
  14.     let currentDifference = Math.abs(currentTotal - total)
  15.     if (currentDifference > maxDifference) {
  16.       maxDifference = currentDifference
  17.     }
  18.  
  19.     total = currentTotal
  20.   }
  21.  
  22.   let result = maxDifference === 0 ? `Yes, value=${total}` : `No, maxdiff=${maxDifference}`
  23.   console.log(result)
  24. }
Advertisement
Add Comment
Please, Sign In to add comment