es6-array-compose
This package adds a new method to the array prototype, allowing to chain arrays in a single virtual array.
Usage
; var arr1 = 12; var arr2 = 56; arr = arr1; console; // (4) [1,2,5,6] arr1; console; // (5) [1,2,3,5,6] arr2; console; // (5) [1,2,3,4,5,6]
Equality
ES6 proxies are (and there are good reasons for that) opaque. Which means that no matter what:
var arr = arr1; arr !== arr1; //truearr != arr1; //true
As a workaround, you can check equality this way:
arr //truearr //true
Which of course is much slower than the regular equality operation
Cool stuff you can potentially do with it
These are just examples, it doesn't mean that it's a good idea to do things like this, but it will give you some ideas, don't hesitate to share with me any use you may find for this.
Priority queues
var p1 = f1f2f3; var p2 = f4f5f6; var p = p1; p; // This will run all the processes, starting from the p1 priority list, and return an array of all the return values
Board games
Please, note that you should not modify the amount of objects from the list, using push, pop, shift, splice or unshift, since there is no way to know on which array will the element end.
var deck = 'A♥''2♥''3♥''4♥''5♥''6♥''7♥''8♥''9♥''10♥''J♥''Q♥''K♥' 'A♦''2♦''3♦''4♦''5♦''6♦''7♦''8♦''9♦''10♦''J♦''Q♦''K♦' 'A♣''2♣''3♣''4♣''5♣''6♣''7♣''8♣''9♣''10♣''J♣''Q♣''K♣' 'A♠''2♠''3♠''4♠''5♠''6♠''7♠''8♠''9♠''10♠''J♠''Q♠''K♠'; var p1 p2 p3 p4 board deck; // Two cards for each player, and five in the boardp1;p1;p2;p2;p3;p3;p4;p4;board;board;board;board;board; var game = p1; console; { var currentIndex = arraylength temporaryValue randomIndex ; // While there remain elements to shuffle... while 0 !== currentIndex // Pick a remaining element... randomIndex = Math; currentIndex -= 1; // And swap it with the current element. temporaryValue = arraycurrentIndex; arraycurrentIndex = arrayrandomIndex; arrayrandomIndex = temporaryValue; return array;} console;