Group the People Given the Group Size They Belong To LeetCode solution in JavaScript
1/**2* @param {number[]} groupSizes3* @return {number[][]}4*/5var groupThePeople = function (groupSizes) {6let indices = [],7result = [];8groupSizes.forEach((x, idx) => {9if (indices[x]) indices[x].push(idx);10else indices[x] = [idx];11if (indices[x].length === x) {12result.push(indices[x]);13indices[x] = undefined;14}15});16return result;17};