Basically i'm trying to write function that takes GGHTTYYYD and returns 2GH2T3YD. Notice that numbers going first. I'm trying to write it in javascrript. How this can be done? Basically here i s my code:
let s = 'GGHTTYYYD';
const count = (str) => {
let hash = {};
str.split('').forEach((char) => {
hash[char] = hash[char] ? (hash[char] += 1) : 1;
});
return hash
};
now i stuck at converting object named hash to string and filter all "1"