Shortest way to form a string out of a subsequence of a string
I believe your code is O(n^2*m), where n is the target and m is the source. Overall, though, I think there are a lot of readability improvements that could be made here by separating functions and renaming variables (j is a particularly bad contender).
// indexCharacters('hello')
// = {'h':[0],'e':[1],'l':[2,3],'o':[4]}
const indexCharacters = source =&gt; {
    const map = new Map();
    for (let i = 0; i &lt; source.length; i++) {
        const char = source[i];
        if (!map.get(char)) map.set(char,[]);
        map.get(char).push(i);
    }
    return map;
}

// matchLength('abc','abeee') = 2
const matchLength = (source,target) =&gt; {
    let count = 0;
    for (let i=0;i&lt;source.length;++i)
        if (target[count] === source[i])
            ++count;
    return count;
}

const shortestWay = (source, target) =&gt; {
    const all_character_indices = indexCharacters(source);
    let occurrences = 0;
    let targetIndex = 0;
    while (targetIndex &lt; target.length) {
        const starting_indices = all_character_indices.get(target[targetIndex]);
        if (!starting_indices) return -1;
    
        const match_lengths = starting_indices.map(
            sourceIndex=&gt;matchLength(
                source.substr(sourceIndex),
                target.substr(targetIndex)
            )
        );
    
        targetIndex += Math.max(...match_lengths);
        ++occurrences;
    }
    return occurrences;
};

console.log(shortestWay('abc','abcbc'))
console.log(shortestWay('abc','acdbc'))
console.log(shortestWay('xyz','xzyxz'))