Skip to content

Instantly share code, notes, and snippets.

@parkerproject
Created May 4, 2021 19:41
Show Gist options
  • Save parkerproject/2d7c67b2ca19ced8e973d552813b7ddd to your computer and use it in GitHub Desktop.
Save parkerproject/2d7c67b2ca19ced8e973d552813b7ddd to your computer and use it in GitHub Desktop.
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