Created
May 16, 2019 20:54
-
-
Save Lavrend/ddc82d3c903f1b723614896699fec2e7 to your computer and use it in GitHub Desktop.
Revisions
-
Lavrend created this gist
May 16, 2019 .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,23 @@ const arrSame = ['va5ya', '5avya', '5ayva']; const arrDiff = ['cat', 'act', 'car']; const isUniqChars = (arr) => { const sortFn = (a, b) => { if (a > b) return 1; if (b > a) return -1; return 0; }; const getUniqVal = (value, index, self) => { return self.indexOf(value) === index; }; const sorted = arr.map(item => item.split('').sort(sortFn).join('')); return (sorted.filter(getUniqVal)).length <= 1; }; console.log(isUniqChars(arrSame)); // true console.log(isUniqChars(arrDiff)); // false