ErolKZ

Untitled

Jun 8th, 2021
15
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. let input = ['7842'];
  3.  
  4.  
  5. let print = this.print || console.log;
  6. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  7.  
  8.  
  9.  
  10. let inputOne = gets().split('');
  11.  
  12. if (inputOne[0] === '-') {
  13.  
  14. inputOne.shift();
  15.  
  16. }
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. inputOne = inputOne.map(Number);
  24.  
  25. console.log(inputOne);
  26.  
  27. let sum = 0;
  28.  
  29. let sum2 = 0;
  30.  
  31. let str = [];
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. for (let i = 0; i < inputOne.length; i++) {
  39.  
  40. sum = sum + inputOne[i];
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. while (sum > 9) {
  50.  
  51. str = sum.toString();
  52.  
  53. str = str.split('').map(Number);
  54. console.log(str);
  55.  
  56. sum = 0;
  57.  
  58. for (let j = 0; j < str.length; j++) {
  59.  
  60.  
  61. sum = sum + str[j];
  62.  
  63. }
  64.  
  65. }
  66.  
  67. console.log(sum);
  68.  
  69.  
  70.  
RAW Paste Data