MCPcopy Index your code
hub / github.com/parse-community/parse-server / getObjectKeyPermutations

Method getObjectKeyPermutations

src/Utils.js:219–236  ·  view source on GitHub ↗

* Creates an object with all permutations of the original keys. * For example, this definition: * ``` * { * a: [true, false], * b: [1, 2], * c: ['x'] * } * ``` * permutates to: * ``` * [ * { a: true, b: 1, c: 'x' }, * { a: true, b: 2, c: 'x' }, *

(object, index = 0, current = {}, results = [])

Source from the content-addressed store, hash-verified

217 * @param {Array} [results=[]] The resulting array of permutations.
218 */
219 static getObjectKeyPermutations(object, index = 0, current = {}, results = []) {
220 const keys = Object.keys(object);
221 const key = keys[index];
222 const values = object[key];
223
224 for (const value of values) {
225 current[key] = value;
226 const nextIndex = index + 1;
227
228 if (nextIndex < keys.length) {
229 Utils.getObjectKeyPermutations(object, nextIndex, current, results);
230 } else {
231 const result = Object.assign({}, current);
232 results.push(result);
233 }
234 }
235 return results;
236 }
237
238 /**
239 * Validates parameters and throws if a parameter is invalid.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected