{"record":{"id":"1aa0d5e589270379","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string-1aa0d5","errorCode":null,"errorMessage":"Argument is not a string","messagePattern":"Argument is not a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckExceeding.js","lineNumber":11,"sourceCode":"/**\n * @function checkExceeding\n * @description - Exceeding words are words where the gap between two adjacent characters is increasing. The gap is the distance in ascii\n * @param {string} str\n * @returns {boolean}\n * @example - checkExceeding('delete') => true, ascii difference - [1, 7, 7, 15, 15] which is incremental\n * @example - checkExceeding('update') => false, ascii difference - [5, 12, 3, 19, 15] which is not incremental\n */\nconst checkExceeding = (str) => {\n  if (typeof str !== 'string') {\n    throw new TypeError('Argument is not a string')\n  }\n\n  const upperChars = str.toUpperCase().replace(/[^A-Z]/g, '') // remove all from str except A to Z alphabets\n\n  const adjacentDiffList = []\n\n  for (let i = 0; i < upperChars.length - 1; i++) {\n    // destructuring current char & adjacent char by index, cause in javascript String is an object.\n    const { [i]: char, [i + 1]: adjacentChar } = upperChars\n\n    if (char !== adjacentChar) {\n      adjacentDiffList.push(\n        Math.abs(char.charCodeAt() - adjacentChar.charCodeAt())\n      )\n    }\n  }\n\n  for (let i = 0; i < adjacentDiffList.length - 1; i++) {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckExceeding.js#L1-L29","documentation":"Thrown as a TypeError by checkExceeding() when str is not a string. The function calls str.toUpperCase().replace(...) and destructures characters by index, all requiring a string receiver. It checks whether gaps between adjacent ASCII codes are monotonically non-decreasing.","triggerScenarios":"Calling checkExceeding(null), checkExceeding(12345), checkExceeding(['d','e','l','e','t','e']), or checkExceeding(undefined).","commonSituations":"Passing a numeric sequence instead of a word; absent JSON fields; values routed through a numeric pipeline.","solutions":["Coerce: checkExceeding(String(word)).","Guard at the boundary with typeof.","Ensure the data source always yields strings."],"exampleFix":"// before\ncheckExceeding(value)\n\n// after\ncheckExceeding(String(value ?? ''))","handlingStrategy":"type-guard","validationCode":"function safeCheckExceeding(str) {\n  if (typeof str !== 'string') {\n    throw new TypeError('Expected a string')\n  }\n  return checkExceeding(str)\n}","typeGuard":"function isString(v) {\n  return typeof v === 'string'\n}","tryCatchPattern":"try {\n  checkExceeding(word)\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'Argument is not a string') {\n    return checkExceeding(String(word))\n  }\n  throw e\n}","preventionTips":["Coerce input with String() before calling.","Validate word fields at the data source.","Use typeof guard for values from untyped sources."],"tags":["type-check","string","ascii","input-validation"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}