Advertisement
nikolayneykov

Untitled

May 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve () {
  2.   let buttons = Array.from(
  3.     document.querySelectorAll('fieldset button')
  4.   ).forEach(x => x.addEventListener('click', getResult))
  5.  
  6.   function getResult () {
  7.     let text = document.querySelector('#input').value
  8.     if (this.parentNode.id === 'filter') {
  9.       let filter = document.getElementById('filterSecondaryCmd').value
  10.       let filterPosition = +document.querySelector('#filterPosition').value
  11.       switch (filter) {
  12.         case 'uppercase':
  13.           text = text.split('').filter(x => x.match(/[A-Z]/))[
  14.             filterPosition - 1
  15.           ]
  16.           break
  17.         case 'lowercase':
  18.           text = text.split('').filter(x => x.match(/[a-z]/))[
  19.             filterPosition - 1
  20.           ]
  21.           break
  22.         case 'nums':
  23.           text = text.split('').filter(x => x.match(/[0-9]/))[
  24.             filterPosition - 1
  25.           ]
  26.           break
  27.       }
  28.       document.querySelector('#output p').textContent += text
  29.     } else if (this.parentNode.id === 'sort') {
  30.       let sort = document.getElementById('sortSecondaryCmd').value
  31.       let sortPosition = +document.querySelector('#sortPosition').value
  32.       switch (sort) {
  33.         case 'A':
  34.           text = text.split('').sort()[sortPosition - 1]
  35.           break
  36.         case 'Z':
  37.           text = text
  38.             .split('')
  39.             .sort()
  40.             .reverse()[sortPosition - 1]
  41.           break
  42.       }
  43.       document.querySelector('#output p').textContent += text
  44.     } else if (this.parentNode.id === 'rotate') {
  45.       let rotate = document.querySelector('#rotateSecondaryCmd').value
  46.       let rotatePosition = +document.querySelector('#rotatePosition').value
  47.       text = text.split('')
  48.       for (let i = 1; i <= rotate; i++) {
  49.         let temp = text.pop()
  50.         text.unshift(temp)
  51.       }
  52.       text = text[rotatePosition - 1]
  53.       document.querySelector('#output p').textContent += text
  54.     } else if (this.parentNode.id === 'get') {
  55.       let getPosition = +document.querySelector('#getPosition').value
  56.       text = text.split('')[getPosition - 1]
  57.       document.querySelector('#output p').textContent += text
  58.     }
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement