Guest User

Untitled

a guest
Aug 19th, 2019
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <body>
  5.  
  6. <form id="frm1">
  7. 1:
  8. <input type="number" name="names" max="9" min="0">
  9. <br> 2:
  10. <input type="number" name="names" max="9" min="0">
  11. <br> 3:
  12. <input type="number" name="names" max="9" min="0">
  13. <br> 4:
  14. <input type="number" name="names" max="9" min="0">
  15. <br> 5:
  16. <input type="number" name="names" max="9" min="0">
  17. <br> 6:
  18. <input type="number" name="names" max="9" min="0">
  19. <br> 7:
  20. <input type="number" name="names" max="9" min="0">
  21. <br>
  22. <br>
  23. </form>
  24.  
  25. <button onclick="myFunction()">Submit</button>
  26.  
  27. <p id="demo"></p>
  28.  
  29. <script>
  30. var array = [];
  31.  
  32. function myFunction() {
  33. var x = document.getElementById("frm1");
  34.  
  35. var i;
  36. for (i = 0; i < x.length; i++) {
  37. array.push(parseInt(x.elements[i].value, 10));
  38. }
  39. document.getElementById("demo").innerHTML = array;
  40. console.log(f(array, 0));
  41. }
  42.  
  43. //var array = [1,2,0,3,0,2,0]
  44.  
  45. function f(array, currentPos) {
  46. console.log(array)
  47. console.log('current pos: ' + currentPos)
  48.  
  49. stepCount = array[currentPos]
  50. console.log('step count: ' + stepCount)
  51.  
  52. if (currentPos + stepCount >= array.length - 1)
  53. return true
  54.  
  55. if (stepCount === 0)
  56. return false
  57.  
  58. possibleSteps = array.slice(currentPos + 1, currentPos + 1 + stepCount)
  59. console.log("possible steps: " + possibleSteps)
  60.  
  61. actualStep = 0
  62. valueOfStep = 0
  63. possibleSteps.forEach((element, index) => {
  64. if (element + index >= valueOfStep) {
  65. actualStep = index
  66. valueOfStep = element + index
  67. }
  68. });
  69.  
  70. console.log('actual step ' + (actualStep + 1))
  71. console.log()
  72. return f(array, currentPos + actualStep + 1)
  73. }
  74. </script>
  75.  
  76. </body>
  77.  
  78. </html>
RAW Paste Data