Advertisement
ekostadinov

[JS] Increasing Sequence

Mar 21st, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title>Find max increasing sequence</title>
  5.     <link href="styles/js-console.css" rel="stylesheet" />
  6. </head>
  7. <body>
  8.  
  9.      <div id="js-console"></div>
  10.     <script src="scripts/js-console.js"></script>
  11.  
  12.     <div id="input-div">
  13.         <h3>To find the maximal increasing sequence of elements in an array.<br />
  14.             Please input array values separated by a single white space.</h3>
  15.        
  16.         <div class="input">
  17.             <label for="inputArr">Your array:</label>
  18.             <input type="text" id="inputArr" />
  19.         </div>
  20.  
  21.         <div id="input-button">
  22.             <input type="button" onclick="findIncreasingEl()" value="Show increasing sequance"/>
  23.         </div>
  24.     </div>
  25.  
  26.     <div id="console"></div>
  27.     <script src="scripts/js-console.js"></script>
  28.    
  29.     <script>
  30.         function findIncreasingEl() {
  31.             var input = document.getElementById("inputArr").value;
  32.             var myArr = input.split(' ');
  33.  
  34.             var sequence = "";
  35.            
  36.             for (var index = 0; index < myArr.length - 1; index++) {
  37.  
  38.                 if (myArr[index] < myArr[index + 1]) {
  39.  
  40.                    
  41.                     sequence += myArr[index];
  42.  
  43.                 }
  44.  
  45.                 if ((myArr[index] > myArr[index + 1]) && sequence.length != 0) { //check for the last sequence element
  46.  
  47.                     sequence += myArr[index];
  48.                     break;
  49.                 }
  50.  
  51.             }
  52.  
  53.             jsConsole.writeLine("The maximal increasing sequence of elements is: " + sequence);
  54.            
  55.  
  56.             jsConsole.writeLine();
  57.  
  58.         }
  59.     </script>
  60.  
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement