Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve () {
- let buttons = Array.from(
- document.querySelectorAll('fieldset button')
- ).forEach(x => x.addEventListener('click', getResult))
- function getResult () {
- let text = document.querySelector('#input').value
- if (this.parentNode.id === 'filter') {
- let filter = document.getElementById('filterSecondaryCmd').value
- let filterPosition = +document.querySelector('#filterPosition').value
- switch (filter) {
- case 'uppercase':
- text = text.split('').filter(x => x.match(/[A-Z]/))[
- filterPosition - 1
- ]
- break
- case 'lowercase':
- text = text.split('').filter(x => x.match(/[a-z]/))[
- filterPosition - 1
- ]
- break
- case 'nums':
- text = text.split('').filter(x => x.match(/[0-9]/))[
- filterPosition - 1
- ]
- break
- }
- document.querySelector('#output p').textContent += text
- } else if (this.parentNode.id === 'sort') {
- let sort = document.getElementById('sortSecondaryCmd').value
- let sortPosition = +document.querySelector('#sortPosition').value
- switch (sort) {
- case 'A':
- text = text.split('').sort()[sortPosition - 1]
- break
- case 'Z':
- text = text
- .split('')
- .sort()
- .reverse()[sortPosition - 1]
- break
- }
- document.querySelector('#output p').textContent += text
- } else if (this.parentNode.id === 'rotate') {
- let rotate = document.querySelector('#rotateSecondaryCmd').value
- let rotatePosition = +document.querySelector('#rotatePosition').value
- text = text.split('')
- for (let i = 1; i <= rotate; i++) {
- let temp = text.pop()
- text.unshift(temp)
- }
- text = text[rotatePosition - 1]
- document.querySelector('#output p').textContent += text
- } else if (this.parentNode.id === 'get') {
- let getPosition = +document.querySelector('#getPosition').value
- text = text.split('')[getPosition - 1]
- document.querySelector('#output p').textContent += text
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement