Such a quick question. What if you have two arrays of objects and you want to "align" these arrays of objects so that you can make sure that each object in the array is in order, like the other array? What if you do not know what keys and values ββany objects inside arrays contain ... Significantly less than in what order they even exist?
So you need a "WildCard expression" for your [].filter , [].map , etc. How do you get a wild card expression?
var jux = (function(){ 'use strict'; function wildExp(obj){ var keysCrude = Object.keys(obj), keysA = ('a["' + keysCrude.join('"], a["') + '"]').split(', '), keysB = ('b["' + keysCrude.join('"], b["') + '"]').split(', '), keys = [].concat(keysA, keysB) .sort(function(a, b){ return a.substring(1, a.length) > b.substring(1, b.length); }); var exp = keys.join('').split(']b').join('] > b').split(']a').join('] || a'); return exp; } return { sort: wildExp }; })(); var sortKeys = { k: 'v', key: 'val', n: 'p', name: 'param' }; var objArray = [ { k: 'z', key: 'g', n: 'a', name: 'b' }, { k: 'y', key: 'h', n: 'b', name: 't' }, { k: 'x', key: 'o', n: 'a', name: 'c' } ]; var exp = jux.sort(sortKeys); console.log('@juxSort Expression:', exp); console.log('@juxSort:', objArray.sort(function(a, b){ return eval(exp); }));
You can also use this iteration function for each object to create the best collective expression for all keys in each of your objects, and then filter the array this way.
This is a small fragment from the Juxtapose API, which I have almost completed, which does this, equality of objects with exceptions, unity of objects and condensation of the array. If this is what you need or want for your project, please comment and I will make lib available sooner rather than later.
Hope this helps! Happy coding :)