{"record":{"id":"2c39938b82329f73","repo":"TheAlgorithms/JavaScript","slug":"provided-input-is-not-an-array","errorCode":null,"errorMessage":"Provided input is not an array","messagePattern":"Provided input is not an array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Bit-Manipulation/GenerateSubSets.js","lineNumber":11,"sourceCode":"/**\n * @function generateSubSets\n * @param {Array} inputArray\n * @returns {Array}\n * @example [1,2] -> [[],[1],[2],[1,2]]\n */\n\n// The time complexity of this algorithm is BigO(2^n) where n is the length of array\nfunction generateSubSets(inputArray) {\n  if (!Array.isArray(inputArray)) {\n    throw new Error('Provided input is not an array')\n  }\n  if (inputArray.length > 32) {\n    throw new RangeError('Error size should be less than equal to 32')\n  }\n  let arrayLength = inputArray.length\n  let subSets = []\n  // loop till (2^n) - 1\n  for (let i = 0; i < 1 << arrayLength; i++) {\n    let subSet = []\n    for (let j = 0; j < arrayLength; j++) {\n      // 1 << j it shifts binary digit 1 by j positions and then we perform\n      // and by AND operation we are checking whetheer jth bit\n      // in i is set to 1 if result is non zero just add into set\n      if (i & (1 << j)) {\n        subSet.push(inputArray[j])\n      }\n    }\n    subSets.push(subSet)","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Bit-Manipulation/GenerateSubSets.js#L1-L29","documentation":"generateSubSets builds the power set by indexing inputArray[j] for each set bit, so it requires a real Array. The guard uses Array.isArray to reject iterables that are not arrays (Sets, strings, generators) which would break the indexed access.","triggerScenarios":"Passing a Set, a string, a Map, an object, null, undefined, a NodeList, or any non-Array iterable.","commonSituations":"Converting a Set to subsets without [...set], passing a string expecting character subsets, or handing in a library collection object.","solutions":["Pass an Array: generateSubSets([1,2,3]).","Spread other iterables first: generateSubSets([...mySet]).","For characters, split the string: generateSubSets(str.split(''))."],"exampleFix":"// before\ngenerateSubSets(new Set([1,2,3]))\n// after\ngenerateSubSets([...new Set([1,2,3])])","handlingStrategy":"validation","validationCode":"function subsetsSafe(iter) {\n  const arr = Array.isArray(iter) ? iter : Array.from(iter);\n  return generateSubSets(arr);\n}","typeGuard":"/** @param {unknown} x @returns {x is unknown[]} */\nconst isArray = x => Array.isArray(x);","tryCatchPattern":"try { return generateSubSets(input); }\ncatch (e) {\n  if (e instanceof Error && /not an array/.test(e.message) && input != null) {\n    return generateSubSets(Array.from(input));\n  }\n  throw e;\n}","preventionTips":["Spread Sets/iterables before calling: generateSubSets([...set]).","Split strings into char arrays when character subsets are wanted.","Wrap external collections with Array.from at the boundary."],"tags":["bit-manipulation","power-set","type-validation","array"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}