Last active
April 21, 2021 13:48
-
-
Save vipul-zambare006/3b853d918d83a19face4d02b5f55277a to your computer and use it in GitHub Desktop.
Common interview coding questions
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
//Common algorithm to calculate frequency of each character or number in an array | |
function frequencyCounter(arr) { | |
let result = {}; | |
arr.forEach((i) => { | |
if (result[i]) { | |
result[i]++; | |
} else { | |
result[i] = 1; | |
} | |
}); | |
//arr.forEach((i) => result[i] ? result[i]++ : result[i]=1); //one liner | |
console.log(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment