Adding Spaces to a String LeetCode solution in JavaScript
1/**2* @param {string} s3* @param {number[]} spaces4* @return {string}5*/6var addSpaces = function (s, spaces) {7let words = spaces.map((space, index) =>8s.slice(index == 0 ? 0 : spaces[index - 1], space)9);10words.push(s.slice(spaces[spaces.length - 1]));11return words.join(" ");12};