Skip to content

Instantly share code, notes, and snippets.

@vipul-zambare006
Last active April 21, 2021 13:48
Show Gist options
  • Save vipul-zambare006/3b853d918d83a19face4d02b5f55277a to your computer and use it in GitHub Desktop.
Save vipul-zambare006/3b853d918d83a19face4d02b5f55277a to your computer and use it in GitHub Desktop.
Common interview coding questions
//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