Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // our array (unsorted)
- let array = [1,3,5,2,4,7,9,6,8,11,15,14,13,12];
- // for loop
- for(let i = 0; i < array.length; i++)
- {
- }
- // reverse for loop
- for(let i = array.length - 1; i >= 0; i--)
- {
- }
- // for loop (JS Edition)
- for(let i in array)
- {
- }
- // better for loop (JS Edition)
- for(let obj of array)
- {
- }
- // simpler for loop (JS Edition)
- array.forEach(obj=>{
- });
- // static function (Function)
- function GetObject(x)
- {
- if(!this.selectedObject || this.selectedObject != x) this.selectedObject = x;
- if(!this.selectedIndex) this.selectedIndex = 0;
- if(x[this.selectedIndex]) return x[this.selectedIndex++];
- else
- {
- this.selectedObject = null;
- this.selectedIndex = 0;
- return undefined;
- }
- }
- // static function (Usage)
- let obj;
- while(obj = GetObject(array)) { }
- // recursive function (LMAO)
- function RecurseObject(array, i)
- {
- let obj = array[i];
- if(array[++i])
- RecurseObject(i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement