SHARE
TWEET

Find Alpha Numbers

xoxama Feb 21st, 2020 (edited) 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. >> Find Alpha Numbers
  2.  
  3. const input = ['135', '357', '791', '357', '913', '579', '135'];
  4. const print = this.print || console.log;
  5. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  6.  
  7. const N = 7;
  8. let arrN = [];
  9.  
  10. for (let i = 0; i < N; i++) {
  11.   const num = +gets();
  12.   let max = 0;
  13.   let mid = 0;
  14.   let min = 0;
  15.   let maxMin = 0;
  16.   let maxMid = 0;
  17.   let midMin = 0;
  18.  
  19.   if (num >= 100 && num <= 999) {
  20.     arrN = num.toString().split('').map((el) => +el); // [ 9, 0, 9 ]
  21.     max = Math.max(...arrN); // 9
  22.     min = Math.min(...arrN); // 0
  23.     mid = arrN.reduce((a, b) => a + b, 0) - min - max; // 9
  24.  
  25.     maxMin = max - min;
  26.     maxMid = max - mid;
  27.     midMin = mid - min;
  28.  
  29.     const theBiggest = Math.max(maxMin, maxMid, midMin); // print(theBiggest); // 9
  30.     const sumThree = min + mid + max; // print(sumThree); // 18
  31.     const sumThreeArr = sumThree.toString().split('').map((el) => +el); // print(sumThreeArr); // [ 1, 8 ]
  32.  
  33.     if (theBiggest > sumThreeArr[1]) {
  34.       print(num);
  35.     }
  36.   }
  37. }
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