Created
February 21, 2013 17:09
-
-
Save majgis/5006311 to your computer and use it in GitHub Desktop.
Javascript while loop to deplete an array from either direction.
This file contains 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 x = [1,2,3] | |
//back to front | |
while(x.length){ | |
var value = x.pop(); | |
console.log(value); | |
} | |
//array is now empty, lets replace it | |
var x = [1,2,3] | |
//front to back | |
while(x.length){ | |
var value = x.shift(); | |
console.log(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment