nikolayneykov

Untitled

May 26th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve () {
  2.   let input = document.querySelector('#input').value
  3.   let result = document.querySelector('#resultOutput')
  4.  
  5.   input = input.split('').map(x => Number(x))
  6.   let reduceSum = String(input.reduce((a, b) => a + b))
  7.   let i = reduceSum
  8.   while (i > 9) {
  9.     i = i
  10.       .toString()
  11.       .split('')
  12.       .map(Number)
  13.       .reduce((a, b) => a + b, 0)
  14.   }
  15.  
  16.   input = input.slice(i, input.length)
  17.   input = input.slice(0, input.length - i)
  18.   input = input.join('').match(new RegExp(`.{1,8}`, 'g'))
  19.   let forAscii = []
  20.   input.forEach(x => {
  21.     let digit = parseInt(x, 2)
  22.     forAscii.push(digit)
  23.   })
  24.   let word = forAscii
  25.     .map(x => String.fromCharCode(x))
  26.     .filter(x => /[A-Za-z\s]/.test(x))
  27.     .join('')
  28.   console.log(word)
  29.   result.textContent = word
  30. }
Advertisement
Add Comment
Please, Sign In to add comment