Exp-1

function stringFormated(val){
  const a = val && val.split("");
  let returnVal = '';
  let retA = {}
  let len = 0;
  a.sort().forEach((str,i)=>{
      if(str === a[i+1]){
          len+=1
          returnVal+=str
      } else{
          returnVal+=(str+' ')
          len+=1
          retA[str] = len;
          len = 0
      }
  })
  return retA;
}
stringFormated('aasssddddxx') // {a: 2, d: 4, s: 3, x: 2}