/*You have an array of non-negative integers. You need to calculate the difference between the 1st biggest number and the 2nd biggest number of the array.*/ function diffBig2(arr) { let maxNum = Math.max(arr[0], arr[1]); let secondMax = Math.min(arr[0], arr[1]); for (let j = 1,i = 2; i < arr.length; ++i, ++j){ if (arr[i] > maxNum) { secondMax = maxNum; maxNum = arr[i]; } else if (arr[i] > secondMax) { secondMax = arr[i]; } } return maxNum - secondMax; }