Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.filter('partition', function() {
- //cache for non subsequent calls
- var cache = {};
- var filter = function(arg, len) {
- if(!arg) { return;}
- var chunks = [];
- // create desired number of empty lists
- for(var i=0; i<len; i++){
- chunks.push([]);
- }
- // iterate over elements
- for(var j=0; j<arg.length ;j++)
- {
- chunks[j%len].push(arg[j]);
- }
- //cache for non subsequent calls
- var argString = JSON.stringify(arg);
- var fromCache = cache[argString+len];
- if (JSON.stringify(fromCache) === JSON.stringify(chunks)) {
- return fromCache;
- }
- cache[argString+len] = chunks;
- return chunks;
- };
- return filter;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement