I have an object with keys and values. Each value is an array that describes the position of key in the string.
const input = {
' ': [5],
d: [10],
e: [1],
H: [0],
l: [2,3,9],
o: [4,7],
r: [8],
w: [6],
};
const buildString = (m) => {
}
I heed to return the string Hello world . My solution is shown below:
const buildString = (m) => {
let res = [];
for(let key in m) {
m[key].map(el => {
res[el] = key;
})
}
return res.join('');
}
But I suppose that it can be solved using reduce method. Could someone help me with implementation please? Thanks in advance.