function count(str){
var str = str.replace(/\s*/g,"");
var strCount={};
var newstr=[];
for(var i=0;i<str.length;i++){
if(newstr.indexOf(str[i])==-1){
newstr.push(str[i]);
strCount[str[i]]=1;
}else{
strCount[str[i]]++;
}
}
return strCount;
}
console.log(count('hello world'))