Last active
October 4, 2020 06:47
-
-
Save FreePhoenix888/4fa8c4e4e21709a6b3412a7c9c4e00f1 to your computer and use it in GitHub Desktop.
This file contains 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 characters
function aclean(arr) { | |
let map = new Map(); | |
for (let word of arr) { | |
// разбиваем слово на буквы, сортируем и объединяем снова в строку | |
let sorted = word.toLowerCase().split("").sort().join(""); // (*) | |
map.set(sorted, word); | |
} | |
return Array.from(map.values()); | |
} | |
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"]; | |
alert( aclean(arr) ); | |
/* For objects | |
function aclean(arr) { | |
let obj = {}; | |
for (let i = 0; i < arr.length; i++) { | |
let sorted = arr[i].toLowerCase().split("").sort().join(""); | |
obj[sorted] = arr[i]; | |
} | |
return Object.values(obj); | |
} | |
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"]; | |
alert( aclean(arr) );*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment