{"record":{"id":"b3f14e1378c16885","repo":"TheAlgorithms/JavaScript","slug":"invalid-input-b3f14e","errorCode":null,"errorMessage":"Invalid input","messagePattern":"Invalid input","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Project-Euler/Problem035.js","lineNumber":16,"sourceCode":"/**\n * Problem 35 - Circular primes\n *\n * @see {@link https://projecteuler.net/problem=35}\n *\n * The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\n * There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\n * How many circular primes are there below one million?\n *\n * @author ddaniel27\n */\nimport { sieveOfEratosthenes } from '../Maths/SieveOfEratosthenes'\n\nfunction problem35(n) {\n  if (n < 2) {\n    throw new Error('Invalid input')\n  }\n  // Get a list of primes without 0, 2, 4, 5, 6, 8; this discards the circular primes 2 & 5\n  const list = sieveOfEratosthenes(n).filter(\n    (prime) => !prime.toString().match(/[024568]/)\n  )\n\n  const result = list.filter((number, _idx, arr) => {\n    const str = String(number)\n    for (let i = 0; i < str.length; i++) {\n      // Get all rotations of the number\n      const rotation = str.slice(i) + str.slice(0, i)\n      if (!arr.includes(Number(rotation))) {\n        // Check if the rotation is prime\n        return false\n      }\n    }\n    return true // If all rotations are prime, then the number is circular prime\n  })","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Project-Euler/Problem035.js#L1-L34","documentation":"Thrown by `problem35(n)` (Project Euler #35, circular primes) when `n < 2`. The function calls `sieveOfEratosthenes(n)` which needs at least 2 to produce primes, so smaller bounds are rejected. The message is generic. Non-number inputs bypass the guard.","triggerScenarios":"Call `problem35(0)`, `problem35(1)`, `problem35(-10)`. `n = 2` passes and the sieve returns [2] (then filtered out by the digit regex).","commonSituations":"Defaulting a 'primes below N' field to 0 or 1, off-by-one boundary confusion, or a request param parsed as 1.","solutions":["Validate `n >= 2` and is a finite integer upstream.","Coerce with `Number(n)` so string/undefined inputs are caught.","Pick a sensible default (e.g. 1000000) when the field is missing."],"exampleFix":"// before\nproblem35(bound) // bound could be 1\n\n// after\nconst n = Number(bound)\nif (!Number.isInteger(n) || n < 2) throw new RangeError('n must be an integer >= 2')\nproblem35(n)","handlingStrategy":"validation","validationCode":"const n = Number(bound)\nif (!Number.isInteger(n) || n < 2) {\n  throw new RangeError('n must be an integer >= 2')\n}\nproblem35(n)","typeGuard":"const isIntAtLeast2 = (x) => typeof x === 'number' && Number.isInteger(x) && x >= 2","tryCatchPattern":null,"preventionTips":["Coerce with Number() so undefined/NaN do not bypass the guard.","Pick a sensible default (e.g. 1000000) when the bound is missing.","Validate at the boundary, not at the call site."],"tags":["range-validation","project-euler","primes","circular-primes"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}