emotrend

crossword

Feb 2nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. function solve() {
  2. let outputP = document.querySelector('#output p');
  3. let inputText = document.getElementById('input');
  4. let filterButton = document.querySelector('#filter button');
  5. let sortButton = document.querySelector('#sort button');
  6. let rotateButton = document.querySelector('#rotate button');
  7. let getButton = document.querySelector('#get button');
  8.  
  9. filterButton.addEventListener('click', () => {
  10. let currInput = inputText.value;
  11. let secondaryCommand = document.getElementById('filterSecondaryCmd').value;
  12. let secondaryPosition = Number(document.getElementById('filterPosition').value);
  13. let tempResult = '';
  14. let temp = '';
  15.  
  16. if (secondaryCommand === 'uppercase') {
  17. let pattern = /[A-Z]+/g;
  18. temp = currInput.split('').filter((el) => el.match(pattern));
  19. tempResult = temp[secondaryPosition - 1];
  20. } else if (secondaryCommand === 'lowercase') {
  21. let pattern = /[a-z]+/g
  22. temp = currInput.split('').filter((el) => el.match(pattern));
  23. tempResult = temp[secondaryPosition - 1];
  24. } else if (secondaryCommand === 'nums') {
  25. let pattern = /[0-9]+/g
  26. temp = currInput.split('').filter((el) => el.match(pattern));
  27. tempResult = temp[secondaryPosition - 1];
  28. }
  29.  
  30. outputP.textContent += tempResult;
  31. });
  32.  
  33. sortButton.addEventListener('click', () => {
  34. let currInput = inputText.value;
  35. let secondaryCommand = document.getElementById('sortSecondaryCmd').value;
  36. let secondaryPosition = Number(document.getElementById('sortPosition').value);
  37. let tempResult = '';
  38.  
  39. if (secondaryCommand === 'A') {
  40. let temp = currInput.split('').sort((a, b) => a.localeCompare(b)).join('');
  41. tempResult = temp[secondaryPosition - 1];
  42. } else if (secondaryCommand === 'Z') {
  43. let temp = currInput.split('').sort((a, b) => b.localeCompare(a)).join('');
  44. tempResult = temp[secondaryPosition - 1];
  45. }
  46.  
  47. outputP.textContent += tempResult;
  48.  
  49. });
  50.  
  51. rotateButton.addEventListener('click', () => {
  52. let currInput = inputText.value;
  53. let secondaryCommand = Number(document.getElementById('rotateSecondaryCmd').value);
  54. let secondaryPosition = Number(document.getElementById('rotatePosition').value);
  55.  
  56. currInput = currInput.split('');
  57.  
  58. for (let i = 0; i < secondaryCommand; i++) {
  59. currInput.unshift(currInput.pop());
  60. }
  61.  
  62. outputP.textContent += currInput[secondaryPosition - 1];
  63. });
  64.  
  65. getButton.addEventListener('click', () => {
  66. let currInput = inputText.value;
  67. let getPosition = Number(document.getElementById('getPosition').value);
  68.  
  69. outputP.textContent += currInput[getPosition - 1];
  70. });
  71. }
Advertisement
Add Comment
Please, Sign In to add comment