Adding Spaces to a String LeetCode solution in JavaScript

1
/**
2
* @param {string} s
3
* @param {number[]} spaces
4
* @return {string}
5
*/
6
var addSpaces = function (s, spaces) {
7
let words = spaces.map((space, index) =>
8
s.slice(index == 0 ? 0 : spaces[index - 1], space)
9
);
10
words.push(s.slice(spaces[spaces.length - 1]));
11
return words.join(" ");
12
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0