2017-02-25 71 views
0

完全刪除重複行我有一個JavaScript下面的列表。的JavaScript - 從陣列

var list = [{ 
    ID: "2566", 
    NAME: "ENTERPRISE EXPENSE", 
    EXECUTE: "LOAD_DIMENTION", 
    TYPE: "PROCEDURE" 
    }, 
    { 
    ID: "1234", 
    NAME: "LOAD EXPENSE FACT", 
    EXECUTE: "LOAD_EXPENSE_FACT", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    ID: "RI0031", 
    NAME: "LOAD HEAD COUNT", 
    EXECUTE: "LOAD_HEADCOUNT_FACT", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    NAME: "Not Required", 
    EXECUTE: "Not Required", 
    TYPE: "Not Required" 
    }, 
    { 
    NAME: "Duplicate", 
    EXECUTE: "Duplicate", 
    TYPE: "Duplicate" 
    }, 
    { 
    ID: "RI04", 
    NAME: "CALCULATE FAST", 
    EXECUTE: "FF_CALC", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    NAME: "FORMULAS", 
    EXECUTE: "FF_CALC", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    ID: "RI0031", 
    NAME: "LOAD HEAD COUNT", 
    EXECUTE: "LOAD_HEADCOUNT_FACT", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    ID: "RI04", 
    NAME: "CALCULATE FAST", 
    EXECUTE: "FF_CALC", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    NAME: "FORMULAS", 
    EXECUTE: "FF_CALC", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    ID: "RID005", 
    NAME: "CALCULATE FAST GROUP", 
    EXECUTE: "FF_CALC", 
    TYPE: "STORED PROCEDURE" 
    }, 
    { 
    NAME: "Not Required", 
    EXECUTE: "Not Required", 
    TYPE: "Not Required" 
    }, 
    { 
    NAME: "Duplicate", 
    EXECUTE: "Duplicate", 
    TYPE: "Duplicate" 
    } 
]; 

此列表有許多重複的行。我想刪除所有重複的行。

對象可以有更多的10種性質也,所以檢查每個屬性是不是解決辦法。另外,無論我上網的方式是1維陣列還是刪除特定屬性的重複。 我怎樣才能保持一個包含所有行唯一一個列表?

+1

我能想到的,是比較JSON對象的字符串化版本。像這樣:'JSON.stringify(obj1)=== JSON.stringify(obj2)'。我猜想這個速度足夠快,但元素屬性的順序很重要。這是一個問題嗎? – Scalpweb

+0

沒有訂單不是問題。但即使我將每一行與所有其他行進行比較,這個過程是不是會太慢?隨着列表大小的增加,複雜度將增加。 –

+0

「善良的用戶」的答案正是我想到的。 JSON.stringify過程是比較JS中2個對象的最快方法。我會說你必須制定一些基準來檢查它是否足夠快,但它應該沒問題。 – Scalpweb

回答

2

the MDN article on JSON.stringify

0不保證非陣列對象的個

屬性以任何特定的順序來字符串化。不要依賴於字符串化中同一對象內的屬性排序。

代替比較每個的JSON字符串化的直接對象,應該首先使用Object.entries獲得的[key, value]對陣列,並且通過key字符串值排序。不管JSON.stringify的實現如何,這個排序的條目數組可以被安全地字符串化和比較。

注意我下面的例子使用了最新的ES6功能,包括SetObject.entries。要將此代碼轉換爲ES5並運行它,請訪問https://babeljs.io/repl/

function deepUnique (array) { 
 
    return [...new Set(array.map(e => JSON.stringify(Object.entries(e).sort(compareEntriesByKey))))].map(e => objectFromEntries(JSON.parse(e))) 
 
} 
 

 
function compareEntriesByKey (a, b) { 
 
    return a[0] < b[0] ? -1 : a[0] === b[0] ? 0 : 1 
 
} 
 

 
function objectFromEntries (entries) { 
 
    let result = {} 
 
    entries.forEach(e => result[e[0]] = e[1]) 
 
    return result 
 
} 
 

 
var list = [{ 
 
    ID: "2566", 
 
    NAME: "ENTERPRISE EXPENSE", 
 
    EXECUTE: "LOAD_DIMENTION", 
 
    TYPE: "PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "1234", 
 
    NAME: "LOAD EXPENSE FACT", 
 
    EXECUTE: "LOAD_EXPENSE_FACT", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RI0031", 
 
    NAME: "LOAD HEAD COUNT", 
 
    EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "Not Required", 
 
    EXECUTE: "Not Required", 
 
    TYPE: "Not Required" 
 
    }, 
 
    { 
 
    NAME: "Duplicate", 
 
    EXECUTE: "Duplicate", 
 
    TYPE: "Duplicate" 
 
    }, 
 
    { 
 
    ID: "RI04", 
 
    NAME: "CALCULATE FAST", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "FORMULAS", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RI0031", 
 
    NAME: "LOAD HEAD COUNT", 
 
    EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RI04", 
 
    NAME: "CALCULATE FAST", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "FORMULAS", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RID005", 
 
    NAME: "CALCULATE FAST GROUP", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "Not Required", 
 
    EXECUTE: "Not Required", 
 
    TYPE: "Not Required" 
 
    }, 
 
    { 
 
    NAME: "Duplicate", 
 
    EXECUTE: "Duplicate", 
 
    TYPE: "Duplicate" 
 
    } 
 
]; 
 

 
console.log(deepUnique(list))

感謝Kind user創建an answer using both JSON and Set之前,我貼我的。

+2

感謝您瞭解'Object#entries'的工作原理。 –

2

這將從對象的數組中刪除確切重複。

var list = [{ ID: "2566", NAME: "ENTERPRISE EXPENSE", EXECUTE: "LOAD_DIMENTION", TYPE: "PROCEDURE" }, 
 
    { ID: "1234", NAME: "LOAD EXPENSE FACT", EXECUTE: "LOAD_EXPENSE_FACT", TYPE: "STORED PROCEDURE" }, 
 
    { ID: "RI0031", NAME: "LOAD HEAD COUNT", EXECUTE: "LOAD_HEADCOUNT_FACT", TYPE: "STORED PROCEDURE" }, 
 
    {NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required"}, 
 
    {NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate"}, 
 
    { ID: "RI04", NAME: "CALCULATE FAST", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, 
 
    { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, 
 
    { ID: "RI0031", NAME: "LOAD HEAD COUNT", EXECUTE: "LOAD_HEADCOUNT_FACT", TYPE: "STORED PROCEDURE" }, 
 
    { ID: "RI04", NAME: "CALCULATE FAST", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, 
 
    { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, 
 
    {ID: "RID005",NAME: "CALCULATE FAST GROUP",EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, 
 
    {NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required"}, 
 
    {NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate"}]; 
 
     
 
var filtered = [...new Set(list.map(v => JSON.stringify(v)))]; 
 

 
console.log(filtered.map(v => JSON.parse(v)));

+0

是的,它的工作很好。感謝您的解決方案。但是,如果對象屬性的順序被改變,那麼它引起的問題。 –

0

Stringifies的所有元素,並同時檢查是否存在類似的人,然後分析它們。 JSON.stringify()JSON.parse()不是快得令人難以置信,雖然。記住這一點,如果你的物體非常大。

var list = [{ 
 
    ID: "2566", 
 
    NAME: "ENTERPRISE EXPENSE", 
 
    EXECUTE: "LOAD_DIMENTION", 
 
    TYPE: "PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "1234", 
 
    NAME: "LOAD EXPENSE FACT", 
 
    EXECUTE: "LOAD_EXPENSE_FACT", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RI0031", 
 
    NAME: "LOAD HEAD COUNT", 
 
    EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "Not Required", 
 
    EXECUTE: "Not Required", 
 
    TYPE: "Not Required" 
 
    }, 
 
    { 
 
    NAME: "Duplicate", 
 
    EXECUTE: "Duplicate", 
 
    TYPE: "Duplicate" 
 
    }, 
 
    { 
 
    ID: "RI04", 
 
    NAME: "CALCULATE FAST", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "FORMULAS", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RI0031", 
 
    NAME: "LOAD HEAD COUNT", 
 
    EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RI04", 
 
    NAME: "CALCULATE FAST", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "FORMULAS", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    ID: "RID005", 
 
    NAME: "CALCULATE FAST GROUP", 
 
    EXECUTE: "FF_CALC", 
 
    TYPE: "STORED PROCEDURE" 
 
    }, 
 
    { 
 
    NAME: "Not Required", 
 
    EXECUTE: "Not Required", 
 
    TYPE: "Not Required" 
 
    }, 
 
    { 
 
    NAME: "Duplicate", 
 
    EXECUTE: "Duplicate", 
 
    TYPE: "Duplicate" 
 
    } 
 
]; 
 

 
function removeDuplicates(list) { 
 
    return list.reduce(function(memo, obj) { 
 
    var string = JSON.stringify(obj); 
 

 
    if (memo.indexOf(string) === -1) { 
 
     memo.push(string); 
 
    } 
 

 
    return memo; 
 
    }, []).map(function(stringified) { 
 
    return JSON.parse(stringified); 
 
    }); 
 
} 
 

 
list = removeDuplicates(list); 
 
console.log(list);

0

如下片段將通過構建一個哈希映射與JSON字符串化密鑰和相應的對象的項目,如值移除重複。通過不對這些值進行字符串化,我們保留它們的引用。所以這裏沒有使用JSON.parse()操作。

function removeDupes(a){ 
 
    var hash = a.reduce(function(h,o){ 
 
         var os = JSON.stringify(o); 
 
         return h[os] ? h : (h[os] = o, h); 
 
    },{}); 
 
    return Object.keys(hash) 
 
       .map(k => hash[k]); 
 
} 
 

 
var list = [{  ID: "2566", 
 
       NAME: "ENTERPRISE EXPENSE", 
 
      EXECUTE: "LOAD_DIMENTION", 
 
       TYPE: "PROCEDURE" 
 
      }, 
 
      {  ID: "1234", 
 
       NAME: "LOAD EXPENSE FACT", 
 
      EXECUTE: "LOAD_EXPENSE_FACT", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RI0031", 
 
       NAME: "LOAD HEAD COUNT", 
 
      EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "Not Required", 
 
      EXECUTE: "Not Required", 
 
       TYPE: "Not Required" 
 
      }, 
 
      { 
 
       NAME: "Duplicate", 
 
      EXECUTE: "Duplicate", 
 
       TYPE: "Duplicate" 
 
      }, 
 
      { 
 
        ID: "RI04", 
 
       NAME: "CALCULATE FAST", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "FORMULAS", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RI0031", 
 
       NAME: "LOAD HEAD COUNT", 
 
      EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RI04", 
 
       NAME: "CALCULATE FAST", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "FORMULAS", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RID005", 
 
       NAME: "CALCULATE FAST GROUP", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "Not Required", 
 
      EXECUTE: "Not Required", 
 
       TYPE: "Not Required" 
 
      }, 
 
      { 
 
       NAME: "Duplicate", 
 
      EXECUTE: "Duplicate", 
 
       TYPE: "Duplicate" 
 
      } 
 
      ], 
 
    res = removeDupes(list); 
 
console.log(res);

但是,如果你想刪除重複項的所有出現,那麼你仍然可以做的工作在一個非常相似的時裝等;

function removeDupes(a){ 
 
    var hash = a.reduce(function(h,o){ 
 
         var os = JSON.stringify(o); 
 
         return h[os] ? (h[os] = false,h) : (h[os] = o, h); 
 
         },{}); 
 
    return Object.keys(hash) 
 
       .reduce((r,k) => hash[k] === false ? r : r.concat(hash[k]),[]); 
 
} 
 

 
var list = [{  ID: "2566", 
 
       NAME: "ENTERPRISE EXPENSE", 
 
      EXECUTE: "LOAD_DIMENTION", 
 
       TYPE: "PROCEDURE" 
 
      }, 
 
      {  ID: "1234", 
 
       NAME: "LOAD EXPENSE FACT", 
 
      EXECUTE: "LOAD_EXPENSE_FACT", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RI0031", 
 
       NAME: "LOAD HEAD COUNT", 
 
      EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "Not Required", 
 
      EXECUTE: "Not Required", 
 
       TYPE: "Not Required" 
 
      }, 
 
      { 
 
       NAME: "Duplicate", 
 
      EXECUTE: "Duplicate", 
 
       TYPE: "Duplicate" 
 
      }, 
 
      { 
 
        ID: "RI04", 
 
       NAME: "CALCULATE FAST", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "FORMULAS", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RI0031", 
 
       NAME: "LOAD HEAD COUNT", 
 
      EXECUTE: "LOAD_HEADCOUNT_FACT", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RI04", 
 
       NAME: "CALCULATE FAST", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "FORMULAS", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
        ID: "RID005", 
 
       NAME: "CALCULATE FAST GROUP", 
 
      EXECUTE: "FF_CALC", 
 
       TYPE: "STORED PROCEDURE" 
 
      }, 
 
      { 
 
       NAME: "Not Required", 
 
      EXECUTE: "Not Required", 
 
       TYPE: "Not Required" 
 
      }, 
 
      { 
 
       NAME: "Duplicate", 
 
      EXECUTE: "Duplicate", 
 
       TYPE: "Duplicate" 
 
      } 
 
      ], 
 
    res = removeDupes(list); 
 
console.log(res);

+0

我知道有'產生衝突的可能性「不指望這一個」'低,但拜託,這是利用對象的唯一標識時,一個很好的例子是爲了。 'var IGNORE = {}'。 。 。 '如果(哈希[K] ===無視){...}' – gyre

+0

@gyre是確保你是正確的,但它只是一個評論十歲上下的代碼並不是爲生產。 – Redu

+0

我明白了你的觀點,但是你會驚訝地發現從SO有多少代碼以某種方式將它變成* someone's * production ...... – gyre

0

你可以使用一個哈希表只排序鍵哈希和使用相同的按鍵對象的數組。

{ 
    "EXECUTE|ID|NAME|TYPE": [ 
     { ID: "2566", NAME: "ENTERPRISE EXPENSE", EXECUTE: "LOAD_DIMENTION", TYPE: "PROCEDURE" }, 
     { ID: "1234", /* ... */ }, 
     { ID: "RI0031", /* ... */ }, 
     { ID: "RI04", /* ... */ }, 
     { ID: "RID005", /* ... */ } 
    ], 
    "EXECUTE|NAME|TYPE": [ 
     { NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required" }, 
     { NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate" }, 
     { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" } 
    ] 
} 

對於濾波,可以首先檢查密鑰,加入了與管,在哈希表中,然後,如果發現,迭代哈希表的陣列,並檢查所有屬性。如果不相等,然後按實際對象的哈希表,並返回true

var list = [{ ID: "2566", NAME: "ENTERPRISE EXPENSE", EXECUTE: "LOAD_DIMENTION", TYPE: "PROCEDURE" }, { ID: "1234", NAME: "LOAD EXPENSE FACT", EXECUTE: "LOAD_EXPENSE_FACT", TYPE: "STORED PROCEDURE" }, { ID: "RI0031", NAME: "LOAD HEAD COUNT", EXECUTE: "LOAD_HEADCOUNT_FACT", TYPE: "STORED PROCEDURE" }, { NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required" }, { NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate" }, { ID: "RI04", NAME: "CALCULATE FAST", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { ID: "RI0031", NAME: "LOAD HEAD COUNT", EXECUTE: "LOAD_HEADCOUNT_FACT", TYPE: "STORED PROCEDURE" }, { ID: "RI04", NAME: "CALCULATE FAST", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { ID: "RID005", NAME: "CALCULATE FAST GROUP", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required" }, { NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate" }], 
 
    result = list.filter(function (hash) { 
 
     return function (o) { 
 
      var keys = Object.keys(o).sort(), 
 
       key = keys.join('|'); 
 

 
      if (!hash[key]) { 
 
       hash[key] = [o]; 
 
       return true; 
 
      } 
 
      if (!hash[key].some(function (p) { return keys.every(function (k) { return o[k] === p[k]; }); })) { 
 
       hash[key].push(o); 
 
       return true; 
 
      } 
 
     }; 
 
    }(Object.create(null))); 
 

 
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

ES6與Map

var list = [{ ID: "2566", NAME: "ENTERPRISE EXPENSE", EXECUTE: "LOAD_DIMENTION", TYPE: "PROCEDURE" }, { ID: "1234", NAME: "LOAD EXPENSE FACT", EXECUTE: "LOAD_EXPENSE_FACT", TYPE: "STORED PROCEDURE" }, { ID: "RI0031", NAME: "LOAD HEAD COUNT", EXECUTE: "LOAD_HEADCOUNT_FACT", TYPE: "STORED PROCEDURE" }, { NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required" }, { NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate" }, { ID: "RI04", NAME: "CALCULATE FAST", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { ID: "RI0031", NAME: "LOAD HEAD COUNT", EXECUTE: "LOAD_HEADCOUNT_FACT", TYPE: "STORED PROCEDURE" }, { ID: "RI04", NAME: "CALCULATE FAST", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { NAME: "FORMULAS", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { ID: "RID005", NAME: "CALCULATE FAST GROUP", EXECUTE: "FF_CALC", TYPE: "STORED PROCEDURE" }, { NAME: "Not Required", EXECUTE: "Not Required", TYPE: "Not Required" }, { NAME: "Duplicate", EXECUTE: "Duplicate", TYPE: "Duplicate" }], 
 
    result = list.filter((map => o => { 
 
     var keys = Object.keys(o).sort(), 
 
      key = keys.join('|'); 
 

 
     if (!map.has(key)) { 
 
      map.set(key, [o]); 
 
      return true; 
 
     } 
 
     if (!map.get(key).some(p => keys.every(k => o[k] === p[k]))) { 
 
      map.get(key).push(o); 
 
      return true; 
 
     } 
 
    })(new Map)); 
 

 
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }