{"record":{"id":"793f2f0094e673c1","repo":"TheAlgorithms/JavaScript","slug":"number-must-be-greater-than-zero-793f2f","errorCode":null,"errorMessage":"Number must be greater than zero.","messagePattern":"Number must be greater than zero\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Maths/IsSquareFree.js","lineNumber":20,"sourceCode":" * Author: Akshay Dubey (https://github.com/itsAkshayDubey)\n * Square free integer: https://en.wikipedia.org/wiki/Square-free_integer\n * function to check if an integer has repeated prime factors.\n * return false if the number as repeated prime factors.\n * else true\n */\n\n/**\n * @function isSquareFree\n * @description -> Checking if number is square free using prime factorization\n * @param {number} number\n * @returns {boolean} true if the number has unique prime factors, otherwise false\n */\n\nimport { PrimeFactors } from './PrimeFactors.js'\nexport const isSquareFree = (number) => {\n  const primeFactorsArray = PrimeFactors(number)\n  if (number <= 0) {\n    throw new Error('Number must be greater than zero.')\n  }\n  return primeFactorsArray.length === new Set(primeFactorsArray).size\n}\n","sourceCodeStart":2,"sourceCodeEnd":24,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/IsSquareFree.js#L2-L24","documentation":"The isSquareFree function checks whether a number has no repeated prime factors by computing its prime factorization. The guard requires number > 0 because prime factorization is only defined for positive integers. Important: PrimeFactors(number) is called at line 19 BEFORE the guard at line 20, so for non-positive input PrimeFactors may throw its own error first depending on its implementation.","triggerScenarios":"Calling isSquareFree(0) or isSquareFree(-12). Any non-positive integer triggers this error (or potentially an earlier error from PrimeFactors).","commonSituations":"Processing sequences that include zero, negative deltas or coordinates, uninitialized variables defaulting to 0, or data streams containing sentinel zero values.","solutions":["Pass a positive integer to isSquareFree.","Guard the input with a positivity check before calling to avoid relying on internal ordering.","Filter zero and negative values from data streams before invoking."],"exampleFix":"// before\nisSquareFree(x)\n// after\nif (!Number.isInteger(x) || x <= 0) return false\nisSquareFree(x)","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(number) || number <= 0) {\n  throw new RangeError('number must be a positive integer')\n}\nisSquareFree(number)","typeGuard":"const isPositiveInteger = (n) => typeof n === 'number' && Number.isInteger(n) && n > 0","tryCatchPattern":null,"preventionTips":["Pre-check positivity for number-theory functions before calling.","Be aware that PrimeFactors may run before the internal guard fires, so validate early.","Filter zero and negative values from data streams before processing."],"tags":["math","number-theory","precondition","prime-factorization"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}