How do you ❓ merge & sort 2 arrays with no duplicates?

preview_player
Показать описание
How do you merge & sort 2 arrays with no duplicates?
#javascript #mergearrays #noduplicates

***SAMPLE CODE:
function mergeNoDups(arr1, arr2) {
let newArr = [...arr1, ...arr2];
let mergedArr = [...new Set(newArr)]

return mergedArr
.sort((a,b) **right arrow** a-b)
}
let arr1 = [1,2,3,4]
let arr2 = [4,5,2,7]
let output = mergeNoDups(arr1, arr2)
// output: [ 1, 2, 3, 4, 5, 7 ]

(Note: YouTube doesn't allow the arrow symbol, hence the words instead of the arrow.)
Рекомендации по теме
Комментарии
Автор

Man, I would just throw everything into a set and be done with it

FortniteJoe
welcome to shbcf.ru