Skip to content

Commit c48bd0a

Browse files
day 25 task complete
1 parent 9cab434 commit c48bd0a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

day25/leetcode2722.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// 2722. Join Two Arrays by ID
2+
// URL -> https://leetcode.com/problems/join-two-arrays-by-id/
3+
4+
/**
5+
* @param {Array} arr1
6+
* @param {Array} arr2
7+
* @return {Array}
8+
*/
9+
var join = function (arr1, arr2) {
10+
const joined = [...arr1, ...arr2]
11+
12+
let map = {}
13+
14+
for (let obj of joined) {
15+
let id = obj.id
16+
17+
if (map.hasOwnProperty(id)) {
18+
map[id] = { ...map[id], ...obj }
19+
} else {
20+
map[id] = obj
21+
}
22+
}
23+
24+
return Object.values(map)
25+
};

0 commit comments

Comments
 (0)