Skip to content

Conversation

VincentHan12
Copy link
Collaborator

@VincentHan12 VincentHan12 commented Sep 8, 2025

Summary by CodeRabbit

  • New Features

    • Implemented comprehensive object, array, string, number, and data-structure utilities (e.g., greetings, property access, cloning, searching, filtering, zipping/unzipping).
    • Added array helpers for retrieval, insertion, replacement, and deletion by index or value.
    • Introduced matrix creation and update utilities.
    • Added functional helpers: map, filter, find, and simple function invocation utilities.
    • Provided basic type getter functions (boolean, function, null, number, object, string).
  • Documentation

    • Marked multiple exercises and initial setup sections as completed in the guides.
  • Chores

    • Adjusted editor save actions configuration for linting.

Copy link

coderabbitai bot commented Sep 8, 2025

Walkthrough

Implements numerous previously stubbed JavaScript kata functions across objects/arrays, strings/numbers, and data-structures; adds new type-related utilities and function utilities; updates exports accordingly; adjusts VS Code ESLint save behavior; and marks exercises as completed in READMEs.

Changes

Cohort / File(s) Summary
Editor config
/.vscode/settings.json
Changed editor.codeActionsOnSave.eslint from true to "explicit" and expanded to multi-line object.
Objects & Arrays kata implementations
/3-JSKata/1-objects-and-arrays/kata.js
Implemented all functions: greetings, object property ops (add/delete/access), array CRUD (get/replace/insert/delete), search (findOne/findAll), zipping/unzipping, and exports.
Strings & Numbers utilities
/3-JSKata/2-strings-and-numbers/utilities.js
Implemented type checks, number/string conversions, arithmetic for strings/numbers, simple email regex check, counting/filter helpers; updated implementations without changing exports.
Data Structures: core utilities
/3-JSKata/3-data-structures/getType.js, /3-JSKata/3-data-structures/getValue.js, /3-JSKata/3-data-structures/getPropTypes.js
Implemented type/value accessors and property type collection; exports unchanged.
Data Structures: search/filter
/3-JSKata/3-data-structures/find.js, /3-JSKata/3-data-structures/where.js
Implemented single-match find and multi-match filter based on key-value criteria; retained signatures/exports.
Data Structures: positions & matrix
/3-JSKata/3-data-structures/positions.js, /3-JSKata/3-data-structures/matrix.js
Implemented getFirst/getLast (and began exporting getLast); created n×n zero matrix and cell update.
Types: function utilities
/3-JSKata/4-types/functions.js
Added callsFunction, callsProperty, filter, find, map; exported all.
Types: primitives and objects
/3-JSKata/4-types/types.js
New module providing getters for boolean, function, null, number, object, string; exported all.
Docs updates
/3-JSKata/README.md, /README.md
Marked certain exercises/contents as completed (checkbox updates).

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ObjectsArrays as 1-objects-and-arrays/kata.js
  participant DataStructures as 3-data-structures/*.js

  rect rgb(235, 245, 255)
  note over Caller,ObjectsArrays: Object/Array ops
  Caller->>ObjectsArrays: addName(obj, name)
  ObjectsArrays-->>Caller: newObj
  Caller->>ObjectsArrays: findOneByProperty(arr, {key: val})
  ObjectsArrays-->>Caller: firstMatch | undefined
  end

  rect rgb(240, 255, 240)
  note over Caller,DataStructures: Search/Filter
  Caller->>DataStructures: find(arr, {k:v})
  DataStructures-->>Caller: match | undefined
  Caller->>DataStructures: where(arr, {k:v,...})
  DataStructures-->>Caller: matches[]
  end
Loading
sequenceDiagram
  participant Caller
  participant Matrix as 3-data-structures/matrix.js

  Caller->>Matrix: getMatrix(n)
  Matrix-->>Caller: matrix[n][n] of 0
  Caller->>Matrix: updateMatrix(matrix, [x,y], value)
  Matrix-->>Caller: matrix (mutated)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vincenthan12-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

🧹 Nitpick comments (5)
3-JSKata/README.md (1)

85-88: Tiny copy edit: pluralize “Objects”.

Consider “Objects and arrays” for correctness and consistency.

- - [x] [Object and arrays](./1-objects-and-arrays/README.md) (2hrs)
+ - [x] [Objects and arrays](./1-objects-and-arrays/README.md) (2hrs)
README.md (1)

21-23: Copy edit: standardize “JavaScript Katas”.

Current text has spacing and an apostrophe. Suggest the common form below.

- - [x] 3. [Java Script Kata's](/3-JSKata/README.md) (8hrs)
+ - [x] 3. [JavaScript Katas](/3-JSKata/README.md) (8hrs)
3-JSKata/3-data-structures/positions.js (1)

1-7: LGTM; optionally guard empty/non-array inputs.

If you want safer helpers, return undefined for non-arrays or empty arrays.

-function getFirst(arr) {
-  return arr[0]
-}
+function getFirst(arr) {
+  return Array.isArray(arr) ? arr[0] : undefined
+}
 
-function getLast(arr) {
-  return arr[arr.length - 1]
-}
+function getLast(arr) {
+  return Array.isArray(arr) && arr.length ? arr[arr.length - 1] : undefined
+}
3-JSKata/3-data-structures/matrix.js (1)

1-8: Validate n and simplify construction

Guard invalid n and use Array.from for clarity/perf.

-function getMatrix(n) {
-  let newMatrix = []
-  for (let i = 0; i < n; i++) {
-    const row = Array(n).fill(0)
-    newMatrix.push(row)
-  }
-  return newMatrix
-}
+function getMatrix(n) {
+  if (!Number.isInteger(n) || n < 0) throw new TypeError('n must be a non-negative integer')
+  return Array.from({ length: n }, () => Array(n).fill(0))
+}
3-JSKata/1-objects-and-arrays/kata.js (1)

141-149: Prefer strict equality and for...of

Avoid coercion and use direct element iteration.

 function deleteItem(arr, item) {
-  let newArr = []
-  for (const i in arr) {
-    if (arr[i] != item) {
-      newArr.push(arr[i])
-    }
-  }
-  return newArr
+  const newArr = []
+  for (const el of arr) {
+    if (el !== item) newArr.push(el)
+  }
+  return newArr
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f181481 and b09e2f7.

📒 Files selected for processing (14)
  • .vscode/settings.json (1 hunks)
  • 3-JSKata/1-objects-and-arrays/kata.js (2 hunks)
  • 3-JSKata/2-strings-and-numbers/utilities.js (1 hunks)
  • 3-JSKata/3-data-structures/find.js (1 hunks)
  • 3-JSKata/3-data-structures/getPropTypes.js (1 hunks)
  • 3-JSKata/3-data-structures/getType.js (1 hunks)
  • 3-JSKata/3-data-structures/getValue.js (1 hunks)
  • 3-JSKata/3-data-structures/matrix.js (1 hunks)
  • 3-JSKata/3-data-structures/positions.js (1 hunks)
  • 3-JSKata/3-data-structures/where.js (1 hunks)
  • 3-JSKata/4-types/functions.js (1 hunks)
  • 3-JSKata/4-types/types.js (1 hunks)
  • 3-JSKata/README.md (1 hunks)
  • README.md (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (9)
3-JSKata/2-strings-and-numbers/utilities.js (12)
3-JSKata/3-data-structures/3-tests/getType.test.js (1)
  • getType (1-1)
3-JSKata/2-strings-and-numbers/2-tests/getType.test.js (1)
  • getType (1-1)
3-JSKata/2-strings-and-numbers/2-tests/isNumber.test.js (1)
  • isNumber (1-1)
3-JSKata/2-strings-and-numbers/2-tests/toNumber.test.js (1)
  • toNumber (1-1)
3-JSKata/2-strings-and-numbers/2-tests/isStringNumber.test.js (1)
  • isStringNumber (1-1)
3-JSKata/2-strings-and-numbers/2-tests/add.test.js (1)
  • add (1-1)
3-JSKata/2-strings-and-numbers/2-tests/addStrings.test.js (1)
  • addStrings (1-1)
3-JSKata/2-strings-and-numbers/2-tests/addStringsOrNumbers.test.js (1)
  • addStringsOrNumbers (1-1)
3-JSKata/2-strings-and-numbers/2-tests/isEmail.test.js (1)
  • isEmail (1-1)
3-JSKata/2-strings-and-numbers/2-tests/countIf.test.js (1)
  • countIf (1-1)
3-JSKata/2-strings-and-numbers/2-tests/filterStringsWithCommas.test.js (1)
  • filterStringsWithCommas (1-1)
3-JSKata/2-strings-and-numbers/2-tests/splitStringByCommas.test.js (2)
  • filterStringsWithCommas (2-2)
  • splitStringByCommas (1-1)
3-JSKata/3-data-structures/getType.js (2)
3-JSKata/3-data-structures/3-tests/getType.test.js (1)
  • getType (1-1)
3-JSKata/2-strings-and-numbers/2-tests/getType.test.js (1)
  • getType (1-1)
3-JSKata/3-data-structures/matrix.js (1)
3-JSKata/3-data-structures/3-tests/matrix.test.js (1)
  • matrix (1-1)
3-JSKata/3-data-structures/getValue.js (1)
3-JSKata/3-data-structures/3-tests/getValue.test.js (1)
  • getValue (1-1)
3-JSKata/3-data-structures/getPropTypes.js (1)
3-JSKata/3-data-structures/3-tests/getPropTypes.test.js (1)
  • getPropTypes (1-1)
3-JSKata/3-data-structures/find.js (2)
3-JSKata/3-data-structures/3-tests/find.test.js (1)
  • find (2-2)
3-JSKata/3-data-structures/where.js (1)
  • searchKey (3-3)
3-JSKata/4-types/functions.js (1)
3-JSKata/3-data-structures/matrix.js (1)
  • i (3-3)
3-JSKata/3-data-structures/where.js (1)
3-JSKata/3-data-structures/3-tests/where.test.js (1)
  • where (2-2)
3-JSKata/1-objects-and-arrays/kata.js (2)
3-JSKata/1-objects-and-arrays/1-tests/addName.test.js (2)
  • name (5-5)
  • obj (6-8)
3-JSKata/1-objects-and-arrays/1-tests/hasItem.test.js (2)
  • arr (5-5)
  • arr (16-16)
🔇 Additional comments (4)
.vscode/settings.json (1)

8-10: Confirm intended ESLint behavior on save.

"explicit" disables auto-fix on save and only runs when you trigger “Fix all”. If you intended auto-fix on save, set it to true instead.

-    "source.fixAll.eslint": "explicit"
+    "source.fixAll.eslint": true
3-JSKata/3-data-structures/getValue.js (1)

1-3: LGTM.

Simple and correct for the kata.

3-JSKata/3-data-structures/getType.js (1)

1-3: LGTM with a note on edge cases.

typeof null === 'object' and arrays return 'object'. If tests ever need special handling, consider detecting those explicitly.

3-JSKata/4-types/types.js (1)

1-34: LGTM

Simple getters match intent; no issues spotted.

Comment on lines +13 to +22
function ageOneYear(obj) {
console.log(obj)
let newObj = {
...obj,
age: obj['age'] + 1,
}
console.log(newObj)

return newObj
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove debug logging and streamline

console.log calls are noisy in library code. Simplify return.

-function ageOneYear(obj) {
-  console.log(obj)
-  let newObj = {
-    ...obj,
-    age: obj['age'] + 1,
-  }
-  console.log(newObj)
-
-  return newObj
-}
+function ageOneYear(obj) {
+  return { ...obj, age: obj.age + 1 }
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function ageOneYear(obj) {
console.log(obj)
let newObj = {
...obj,
age: obj['age'] + 1,
}
console.log(newObj)
return newObj
}
function ageOneYear(obj) {
return { ...obj, age: obj.age + 1 }
}
🤖 Prompt for AI Agents
In 3-JSKata/1-objects-and-arrays/kata.js around lines 13 to 22, remove the two
console.log debugging lines and simplify the function to return the updated
object directly; replace the current creation of newObj and intermediate logs by
returning a new object that spreads obj and sets age to obj.age + 1 (no logging,
no unused variables).

Comment on lines +107 to +113
function getItemAtIndex(arr, idx) {
if (arr[idx]) {
return arr[idx]
} else {
return Error()
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Index existence check is incorrect

arr[idx] fails for falsy values (0, '', false). Check bounds instead.

 function getItemAtIndex(arr, idx) {
-  if (arr[idx]) {
-    return arr[idx]
-  } else {
-    return Error()
-  }
+  if (Number.isInteger(idx) && idx >= 0 && idx < arr.length) return arr[idx]
+  return Error()
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getItemAtIndex(arr, idx) {
if (arr[idx]) {
return arr[idx]
} else {
return Error()
}
}
function getItemAtIndex(arr, idx) {
if (Number.isInteger(idx) && idx >= 0 && idx < arr.length) return arr[idx]
return Error()
}
🤖 Prompt for AI Agents
In 3-JSKata/1-objects-and-arrays/kata.js around lines 107 to 113, the current
existence check uses arr[idx] which rejects valid falsy values (0, '', false);
replace it with an explicit bounds check (e.g. idx >= 0 && idx < arr.length) so
valid falsy entries are returned, and return the item when in-bounds otherwise
return a new Error (or appropriate error value/message).

Comment on lines +182 to +192
function findAll(arr, search) {
let newArr = []
let key = Object.keys(search)[0]
let value = search[key]
for (obj of arr) {
if (obj[key] == value) {
newArr.push(obj)
}
}
return newArr
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implicit global in for-of loop

obj is undeclared; declare it.

 function findAll(arr, search) {
-  let newArr = []
-  let key = Object.keys(search)[0]
-  let value = search[key]
-  for (obj of arr) {
+  let newArr = []
+  let key = Object.keys(search)[0]
+  let value = search[key]
+  for (const obj of arr) {
     if (obj[key] == value) {
       newArr.push(obj)
     }
   }
   return newArr
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function findAll(arr, search) {
let newArr = []
let key = Object.keys(search)[0]
let value = search[key]
for (obj of arr) {
if (obj[key] == value) {
newArr.push(obj)
}
}
return newArr
}
function findAll(arr, search) {
let newArr = []
let key = Object.keys(search)[0]
let value = search[key]
for (const obj of arr) {
if (obj[key] == value) {
newArr.push(obj)
}
}
return newArr
}
🤖 Prompt for AI Agents
In 3-JSKata/1-objects-and-arrays/kata.js around lines 182 to 192, the for-of
loop uses an undeclared variable obj causing an implicit global; declare the
loop variable (e.g., change to "for (const obj of arr)" or "for (let obj of
arr)") to avoid polluting global scope and ensure proper block scoping.

Comment on lines +13 to +15
function isStringNumber(str) {
return typeof str == 'string' && !isNaN(str)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Tighten numeric string check

Current logic treats whitespace-only strings as numbers. Use trim + Number.isFinite.

-function isStringNumber(str) {
-  return typeof str == 'string' && !isNaN(str)
-}
+function isStringNumber(str) {
+  return typeof str === 'string' && str.trim() !== '' && Number.isFinite(Number(str))
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isStringNumber(str) {
return typeof str == 'string' && !isNaN(str)
}
function isStringNumber(str) {
return typeof str === 'string'
&& str.trim() !== ''
&& Number.isFinite(Number(str))
}
🤖 Prompt for AI Agents
In 3-JSKata/2-strings-and-numbers/utilities.js around lines 13-15, the
isStringNumber implementation treats whitespace-only strings as numbers; change
the check to first ensure str is a string, then call str.trim() and if the
trimmed string is non-empty convert it with Number(...) and use
Number.isFinite(...) to verify it's a finite numeric value (i.e., return typeof
str === 'string' && str.trim() !== '' && Number.isFinite(Number(str.trim()))).

Comment on lines +33 to +37
function isEmail(str) {
console.log
const emailRegex = /.+@.+\..+/
return emailRegex.test(str)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove stray console.log and anchor regex

The bare console.log is a no-op and may fail linting. Anchor the regex to reduce false positives.

-function isEmail(str) {
-  console.log
-  const emailRegex = /.+@.+\..+/
-  return emailRegex.test(str)
-}
+function isEmail(str) {
+  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
+  return emailRegex.test(str)
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isEmail(str) {
console.log
const emailRegex = /.+@.+\..+/
return emailRegex.test(str)
}
function isEmail(str) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
return emailRegex.test(str)
}
🤖 Prompt for AI Agents
In 3-JSKata/2-strings-and-numbers/utilities.js around lines 33 to 37, remove the
stray bare console.log call and anchor the email regex to avoid false positives;
replace the regex /.+@.+\..+/ with an anchored pattern like /^.+@.+\..+$/ (or a
tighter RFC-compliant pattern if desired) and keep the function returning
emailRegex.test(str).

Comment on lines +10 to +15
function updateMatrix(matrix, coords, value) {
const x = coords[0]
const y = coords[1]
matrix[x][y] = value
return matrix
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Bounds/input checks for coords

Access without validation can throw or corrupt state. Add type/bounds checks.

-function updateMatrix(matrix, coords, value) {
-  const x = coords[0]
-  const y = coords[1]
-  matrix[x][y] = value
-  return matrix
-}
+function updateMatrix(matrix, coords, value) {
+  const [x, y] = coords
+  if (!Array.isArray(matrix) || !Array.isArray(matrix[x])) throw new TypeError('matrix must be a 2D array')
+  if (!Number.isInteger(x) || !Number.isInteger(y) || x < 0 || y < 0 || x >= matrix.length || y >= matrix[x].length) {
+    throw new RangeError('coords out of bounds')
+  }
+  matrix[x][y] = value
+  return matrix
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function updateMatrix(matrix, coords, value) {
const x = coords[0]
const y = coords[1]
matrix[x][y] = value
return matrix
}
function updateMatrix(matrix, coords, value) {
const [x, y] = coords
if (!Array.isArray(matrix) || !Array.isArray(matrix[x])) throw new TypeError('matrix must be a 2D array')
if (
!Number.isInteger(x) ||
!Number.isInteger(y) ||
x < 0 ||
y < 0 ||
x >= matrix.length ||
y >= matrix[x].length
) {
throw new RangeError('coords out of bounds')
}
matrix[x][y] = value
return matrix
}
🤖 Prompt for AI Agents
In 3-JSKata/3-data-structures/matrix.js around lines 10 to 15, the updateMatrix
function writes to matrix[x][y] without validating coords or types; add input
and bounds checks: verify matrix is an array of arrays, coords is an array/tuple
of two finite integers, and value is acceptable for your domain; check 0 <= x <
matrix.length and 0 <= y < matrix[x].length (or handle ragged rows) and throw a
clear TypeError/RangeError if validations fail; only perform the assignment and
return the matrix after all checks pass.

Comment on lines +1 to +20
function where(arr, searchDetails) {
let newArr = []
const searchKey = Object.keys(searchDetails)

for (const obj of arr) {
let match = true

for (const i in searchKey) {
if (obj[searchKey[i]] != searchDetails[searchKey[i]]) {
match = false
}
}

if (match) {
newArr.push(obj)
}
}
console.log(newArr)
return newArr
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove console.log and simplify matching; prefer strict equality.

Unconditional logging is noisy. The loop can be simplified and short-circuited; use === to avoid coercion.

 function where(arr, searchDetails) {
-  let newArr = []
-  const searchKey = Object.keys(searchDetails)
-
-  for (const obj of arr) {
-    let match = true
-
-    for (const i in searchKey) {
-      if (obj[searchKey[i]] != searchDetails[searchKey[i]]) {
-        match = false
-      }
-    }
-
-    if (match) {
-      newArr.push(obj)
-    }
-  }
-  console.log(newArr)
-  return newArr
+  const keys = Object.keys(searchDetails)
+  return arr.filter((obj) => keys.every((k) => obj && obj[k] === searchDetails[k]))
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function where(arr, searchDetails) {
let newArr = []
const searchKey = Object.keys(searchDetails)
for (const obj of arr) {
let match = true
for (const i in searchKey) {
if (obj[searchKey[i]] != searchDetails[searchKey[i]]) {
match = false
}
}
if (match) {
newArr.push(obj)
}
}
console.log(newArr)
return newArr
}
function where(arr, searchDetails) {
const keys = Object.keys(searchDetails)
return arr.filter((obj) => keys.every((k) => obj && obj[k] === searchDetails[k]))
}
🤖 Prompt for AI Agents
In 3-JSKata/3-data-structures/where.js around lines 1-20, remove the console.log
and simplify/short-circuit the matching logic while using strict equality:
compute the searchKeys with Object.keys(searchDetails), iterate over them with a
for...of (or use Array.prototype.every) and break/short-circuit as soon as a
non-match is found, comparing values with === instead of !=; push matching
objects to newArr (or return arr.filter(...) directly) and return the result
without any console output.

Comment on lines +9 to +17
function filter(arr, func) {
const elements = []
for (i in arr) {
if (func(arr[i])) {
elements.push(arr[i])
}
}
return elements
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid for...in on arrays and implicit globals

for...in iterates keys (and inherited) and i is undeclared; use for...of.

 function filter(arr, func) {
   const elements = []
-  for (i in arr) {
-    if (func(arr[i])) {
-      elements.push(arr[i])
-    }
-  }
+  for (const el of arr) {
+    if (func(el)) elements.push(el)
+  }
   return elements
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function filter(arr, func) {
const elements = []
for (i in arr) {
if (func(arr[i])) {
elements.push(arr[i])
}
}
return elements
}
function filter(arr, func) {
const elements = []
for (const el of arr) {
if (func(el)) elements.push(el)
}
return elements
}
🤖 Prompt for AI Agents
In 3-JSKata/4-types/functions.js lines 9-17, the function uses for...in and an
undeclared i which iterates inherited keys and creates an implicit global;
replace it with a proper array iteration (e.g., for (const item of arr) { if
(func(item)) elements.push(item); }) or use arr.forEach/arr.filter, and ensure
any loop variable is declared with let/const to avoid globals.

Comment on lines +19 to +25
function find(arr, func) {
for (i in arr) {
if (func(arr[i])) {
return arr[i]
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Same issue in find

Switch to for...of to avoid global i and prototype keys.

 function find(arr, func) {
-  for (i in arr) {
-    if (func(arr[i])) {
-      return arr[i]
-    }
-  }
+  for (const el of arr) {
+    if (func(el)) return el
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function find(arr, func) {
for (i in arr) {
if (func(arr[i])) {
return arr[i]
}
}
}
function find(arr, func) {
for (const el of arr) {
if (func(el)) return el
}
}
🤖 Prompt for AI Agents
In 3-JSKata/4-types/functions.js around lines 19 to 25, the current
implementation uses "for (i in arr)" which leaks a global i and iterates
prototype keys; replace it with a for...of loop such as "for (const item of
arr)" and call func(item), returning item when true; also ensure the function
returns undefined (or null) explicitly if no element matches.

Comment on lines +27 to +33
function map(arr, func) {
const elements = []
for (i in arr) {
elements.push(func(arr[i]))
}
return elements
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Same issue in map

Use for...of and local variable.

 function map(arr, func) {
   const elements = []
-  for (i in arr) {
-    elements.push(func(arr[i]))
-  }
+  for (const el of arr) {
+    elements.push(func(el))
+  }
   return elements
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function map(arr, func) {
const elements = []
for (i in arr) {
elements.push(func(arr[i]))
}
return elements
}
function map(arr, func) {
const elements = []
for (const el of arr) {
elements.push(func(el))
}
return elements
}
🤖 Prompt for AI Agents
In 3-JSKata/4-types/functions.js around lines 27-33, the map implementation uses
a for-in loop and an undeclared loop variable which can iterate over inherited
properties and leak a global; change it to use a for...of loop with a local loop
variable (e.g., for (const item of arr)) and call func(item) when pushing into
the elements array so iteration is safe and variables are properly scoped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant