Guest User

Untitled

a guest
May 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. const isInteresting = (n, awes) => {
  2. if (n < 98) return 0;
  3. if (n < 100) return 1;
  4.  
  5. const nums = [n, n + 1, n + 2];
  6.  
  7. for (let i = 0; i < nums.length; i += 1) {
  8. const flipped = [];
  9. let copy = nums[i];
  10. let isSame = true;
  11. let isDecr = true;
  12. let isIncr = true;
  13.  
  14. for (copy; copy > 0; copy /= 10) {
  15. const curr = copy % 10;
  16.  
  17. if (flipped.length) {
  18. const prev = flipped[flipped.length - 1];
  19.  
  20. if (prev !== curr) isSame = false;
  21. if (prev + 1 !== curr) isDecr = false;
  22. if (!(prev - 1 === curr || prev + 9 === curr)) isIncr = false;
  23. }
  24.  
  25. flipped.push(curr);
  26.  
  27. if (copy - curr === 0) {
  28. // is awesome could technically be better placed at the beginning
  29. // of the loop. Looks nicer here though.
  30. const isAwes = awes.some(phrase => phrase === nums[i]);
  31. const isSingl = Number(`${flipped.join('')}`) < 10;
  32. const isPalin = Number(`${flipped.join('')}`) === nums[i];
  33. const almostOrYes = i > 0 ? 1 : 2;
  34.  
  35. if (isSingl || isSame || isDecr || isIncr || isPalin || isAwes) return almostOrYes;
  36. }
  37.  
  38. copy -= curr;
  39. }
  40. }
  41. return 0;
  42. };
Add Comment
Please, Sign In to add comment