Created
May 4, 2021 19:41
-
-
Save parkerproject/2d7c67b2ca19ced8e973d552813b7ddd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let result = { | |
unique: [], | |
frequent: [] | |
} | |
const arr1 = ['a', 'b', 'c', 'e', 'j', 'f'] | |
const arr2 = ['a', 'a', 'f', 'b', 'g', 'r', 'e', 'f', 't'] | |
let count = {} | |
arr2.forEach((val)=>{ | |
count[val] = !count.hasOwnProperty(val) ? 1 : count[val]+1 | |
if(!arr1.includes(val)){ | |
result.unique.push(val) | |
} | |
}) | |
const t = Object.values(count) | |
const k = Math.max(...t) | |
const s = Object.keys(count).forEach((val) => { | |
if(count[val] === k) result.frequent.push(val) | |
}) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment