-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path49-group.js
More file actions
42 lines (36 loc) · 1.09 KB
/
49-group.js
File metadata and controls
42 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//2022/04/27
function groupAnagrams(strs){
let dict = {}
strs.map((word) => {
dict[word.split("").sort()]? dict[word.split("").sort()].push(`${word}`) :
dict[word.split("").sort()] = [`${word}`]
})
console.log(Object.values(dict))
return Object.values(dict)
}
groupAnagrams(["eat","tea","tan","ate","nat","bat"])
//2022/04/26
// function groupAnagrams(strs){
// let obj = {}
// strs.map(each => {
// let eachWord = each.split("").sort().join("")
// console.log(eachWord)
// obj[eachWord] ? obj[eachWord].push(each) : obj[eachWord] = [each]
// })
// console.log(Object.values(obj))
// return Object.values(obj)
// }
//2022/04/26 5:00pm - 5: 45pm
// var groupAnagrams = function(strs) {
// let dict = {}
// strs.map(each => {
// let eachArr = [...each].sort()
// //console.log(eachArr)
// if(!dict.hasOwnProperty(eachArr)){
// dict[eachArr] = [`${each}`]
// } else {
// dict[eachArr].push(each)
// }
// })
// return Object.values(dict)
//};