Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. function returnObject(aString){
  2. //object initializer
  3. var obj = {};
  4.  
  5. //loop through letters of string and populate keys
  6. for (i = 0; i < aString.length; i++) {
  7. obj[aString[i]] = (obj[aString[i]] || 0) + 1;
  8. }
  9. //return obj to function
  10. return obj;
  11. }
  12. console.log(returnObject("helloooo"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement