Algorithm for Continuous Number arrangement - Javascript Number Operation

Javascript examples for Number Operation:Integer

Description

Algorithm for Continuous Number arrangement

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*  w w  w .  j ava2  s  . c  o  m*/
var c = 0;
var array_in = [0,0,1,1,3,3,5,5,7,8,8,8,10];
var array_out = array_in.map(function(a,i,arr){return (arr[i] > arr[i-1])?++c:c});
document.write(array_out);
// out == [0,0,1,1,2,2,3,3,4,5,5,5,6]
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials