Advertisement
Guest User

Alpha Number

a guest
Feb 22nd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const input = [
  2. '135',
  3. '357',
  4. '791',
  5. '357',
  6. '913',
  7. '579',
  8. '135'];
  9. const print = this.print || console.log;
  10. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  11.  
  12. const alphaNumber = [];
  13. const inputAsNumbers = [gets(), gets(), gets(), gets(), gets(), gets(), gets()];
  14.  
  15. inputAsNumbers.map((num) => {
  16. const a = +num[0];
  17. const b = +num[1];
  18. const c = +num[2];
  19.  
  20. const biggestNonNegativeDifference = Math.max(
  21. Math.abs(a - b),
  22. Math.abs(b - c),
  23. Math.abs(a - c)
  24. );
  25.  
  26. const resultSum = (a + b + c) % 10;
  27.  
  28. if (resultSum < biggestNonNegativeDifference) {
  29. alphaNumber.push(num);
  30. }
  31. });
  32.  
  33. print(alphaNumber.join(' '));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement