Advertisement
xapu

Untitled

Jul 14th, 2017
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. (function () {
  2. define(['js/xapuJs.js'], function (xapu) {
  3.  
  4. let a = [1, 2, 3, 4, 5]
  5.  
  6. console.log('test')
  7. console.log(xapu.rollLeft(a))
  8.  
  9.  
  10. let theArray = []
  11. let initialized = false
  12. let output = document.getElementById('output')
  13. let input = document.getElementById('input')
  14. document.getElementById('submit').addEventListener('click', submit)
  15. input.addEventListener(
  16. 'keypress',
  17. e => (e.code === 'Enter' ? submit() : '')
  18. )
  19. let commands = {
  20. reverse: function () {
  21. theArray.reverse()
  22. output.value += theArray.join(' ') + '\n'
  23. }
  24. }
  25.  
  26. function submit () {
  27. let commandTokens = input.value.split(' ').filter(e => e !== '')
  28. console.log('Submitted: ' + commandTokens)
  29. if (!initialized) {
  30. theArray = commandTokens.slice(0)
  31. input.value = ''
  32. initialized = true
  33. output.value += theArray.join(' ') + '\n'
  34. return
  35. }
  36. try {
  37. commands[commandTokens[0]](commandTokens.slice(1))
  38. } catch (err) {
  39. output.value += 'Error: invalid command' + '\n'
  40. } finally {
  41. input.value = ''
  42. }
  43. }
  44. })
  45. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement