Skip to content

Instantly share code, notes, and snippets.

@ChathuraGH
Created December 1, 2023 19:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChathuraGH/5125b4a041e2f1b1601d3a2152491db9 to your computer and use it in GitHub Desktop.
Save ChathuraGH/5125b4a041e2f1b1601d3a2152491db9 to your computer and use it in GitHub Desktop.
let str = "atul kumar srivastava";
let obj ={};
for(let s of str)if(!obj[s])obj[s] = 1;else obj[s] = obj[s] + 1;
console.log(obj)
//source
// https://stackoverflow.com/questions/19480916/count-number-of-occurrences-for-each-char-in-a-string
// https://stackoverflow.com/a/60648545/13861187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment