<HTML>
<body>
</body>
<script>
function aclean(arr){
let map = new Map();
for(let word of arr){
let sorted = word
.toLowerCase() // delete the case difference
.split('') //split it to sort
.sort() // sort it to delete the order difference
.join(''); // join to use as a key = one word
map.set(sorted, word);
//set saves keys by the key not by the value,
//the words canoot be saved when word with the same
//key is saved already
//map = is a collection of keyed value
//set = is a colelction of unique value
}
return Array.from(map.values());
}
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];
alert( aclean(arr) );
</script>
</HTML>
<!--
could not actually solve it
but the solution logic was interesting
yes i was a dumb ^^
-->
<body>
</body>
<script>
function aclean(arr){
let map = new Map();
for(let word of arr){
let sorted = word
.toLowerCase() // delete the case difference
.split('') //split it to sort
.sort() // sort it to delete the order difference
.join(''); // join to use as a key = one word
map.set(sorted, word);
//set saves keys by the key not by the value,
//the words canoot be saved when word with the same
//key is saved already
//map = is a collection of keyed value
//set = is a colelction of unique value
}
return Array.from(map.values());
}
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];
alert( aclean(arr) );
</script>
</HTML>
<!--
could not actually solve it
but the solution logic was interesting
yes i was a dumb ^^
-->
댓글
댓글 쓰기