Last active
February 17, 2017 08:47
-
-
Save ovarunendra/58d8ae2e5584852db68e9950e64f2bee to your computer and use it in GitHub Desktop.
Revisions
-
Varunendra Pratap Singh revised this gist
Feb 17, 2017 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,18 @@ function dedup(arr) { return arr.filter(function (el) { var key; if (Object.prototype.toString.call(el) === "[object Object]") { key = JSON.stringify(Object.keys(el).sort()); Object.keys(el).forEach(function(i){ key += JSON.stringify(el[i]); }); } else { key = JSON.stringify(el); } var match = Boolean(hashTable[key]); return (match ? false : hashTable[key] = true); }); } var asd = [1, '1', 1, [1,2], [2,1], [1,2], {a:1, b:2}, {a:2, b:1}, {b:1, a:2}]; console.log(dedup(asd)); -
Varunendra Pratap Singh revised this gist
Feb 16, 2017 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ function dedup(arr) { var hashTable = {}; return arr.filter(function (el) { var key; if (Object.prototype.toString.call(el) === "[object Object]") { key = JSON.stringify(Object.keys(el).sort()) + JSON.stringify(Object.values(el).sort()); } else { key = JSON.stringify(el); } var match = Boolean(hashTable[key]); return (match ? false : hashTable[key] = true); }); } -
Varunendra Pratap Singh created this gist
Feb 16, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ function dedup(arr) { var hashTable = {}; return arr.filter(function (el) { var key; if (Object.prototype.toString.call(el) === "[object Object]") { key = JSON.stringify(Object.keys(el).sort()) + JSON.stringify(Object.values(el).sort()); } else { key = JSON.stringify(el); } var match = Boolean(hashTable[key]); return (match ? false : hashTable[key] = true); }); }