Commit 5747446c authored by Rafael Avaria G's avatar Rafael Avaria G

Missing number in Js

parent fb0ba8ba
function getFrecuency(arr) {
return arr.reduce((acc, ele) => {
if (acc.has(ele)) {
const i = acc.get(ele);
acc.set(ele, i + 1);
} else {
acc.set(ele, 1);
}
return acc;
}, new Map());
}
// Complete the missingNumbers function below.
function missingNumbers(arr, brr) {
const result = [];
const arrF = getFrecuency(arr);
const brrF = getFrecuency(brr);
for ( let value of brrF.keys()) {
if ( arrF.has(value)) {
if ( arrF.get(value) != brrF.get(value)) {
result.push(value);
}
} else {
result.push(value);
}
}
return result.sort(function(a, b) { return a - b; });
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment