SHARE
TWEET

merging and squashing

gskorchev Feb 18th, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const input = [11, 44, 69, 46, 63, 83, 13, 62, 14, 31, 68, 87];
  2. const gets = this.gets || ((input, index) => () => input[index++])(input, 0);
  3. const print = this.print || console.log;
  4.  
  5.  
  6. let n = +gets();
  7. let arr = [];
  8. for (let i = 1; i <= n; i++) {
  9.     let num = +gets();
  10.     arr.push(num)
  11. }
  12. let firstResult = [];
  13. let secondResult = [];
  14.  
  15. for (let i = 0; i < arr.length - 1; i++) {
  16.     let mergingFirstNumber = arr[i] % 10;
  17.     let mergingSecondNumber = Math.floor(arr[i + 1] / 10)
  18.     let squashingFirstNumber = Math.floor(arr[i] / 10);
  19.     let squashingSecondNumber = Math.floor(arr[i + 1] % 10)
  20.     let cdNum = mergingFirstNumber + mergingSecondNumber;
  21.     if (cdNum >= 10) {
  22.         cdNum = cdNum % 10;
  23.     }
  24.     firstResult.push(mergingFirstNumber + "" + mergingSecondNumber)
  25.     secondResult.push(squashingFirstNumber + "" + cdNum + "" + squashingSecondNumber)
  26. }
  27.  
  28. print(firstResult.join(' '));
  29.  
  30. print(secondResult.join(' '));
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