Last active
October 30, 2015 09:38
-
-
Save omeroot/09770dc98e5d082e5105 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var array = []; | |
| function addElement(element){ | |
| for(var i = array.length ; i>0 && element <= array[i-1] ; --i){ | |
| array[i] = array[i-1]; | |
| } | |
| array[i] = element; | |
| } | |
| addElement(5);// array => [5] | |
| addElement(2);// array => [2,5] | |
| addElement(6);// array => [2,5,6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment