Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7f7479a
complete first task.md
VincentHan12 Jun 25, 2025
f669025
complete first task.md
VincentHan12 Jun 25, 2025
87796d2
Merge pull request #38 from JesusFilm/vincenthan12-complete-first-task
VincentHan12 Jul 8, 2025
25f383c
Basics Done.md
VincentHan12 Jul 15, 2025
8cfd62b
complete second task
VincentHan12 Jul 15, 2025
a41163d
Update README.md
VincentHan12 Jul 15, 2025
898811f
Merge pull request #41 from JesusFilm/VincentHan12-complete-2
VincentHan12 Jul 15, 2025
4464a5f
Update README.md
VincentHan12 Jul 16, 2025
dd1bced
Merge pull request #42 from JesusFilm/VincentHan12-objects-task3-done
VincentHan12 Jul 16, 2025
28e3eea
JSKata completed task 2.md
VincentHan12 Jul 17, 2025
36b191e
Merge pull request #43 from JesusFilm/VincentHan12-strings-task3-done
VincentHan12 Jul 17, 2025
407e320
Test 2 Completed
VincentHan12 Jul 21, 2025
70b58bb
Merge branch 'vincenthan12-main' of https://github.com/JesusFilm/reac…
VincentHan12 Jul 21, 2025
d956f4a
Test 1 Complete
VincentHan12 Jul 21, 2025
19e9083
settings update
VincentHan12 Jul 21, 2025
cc71a3e
Test 3 Complete
VincentHan12 Jul 21, 2025
202c6a3
Task 3 Data Structures Complete.md
VincentHan12 Jul 21, 2025
86c88c7
Merge pull request #46 from JesusFilm/VincentHan12-task-3-data
VincentHan12 Jul 21, 2025
e4ee3d2
Update Task 3
VincentHan12 Jul 21, 2025
4cea066
Merge branch 'vincenthan12-main' of https://github.com/JesusFilm/reac…
VincentHan12 Jul 21, 2025
b09e2f7
complete third task
Sep 8, 2025
4f566f1
Task 4 Completed
Oct 28, 2025
422bb7c
first commit
Nov 5, 2025
d6f2a85
Update README.md
VincentHan12 Nov 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
"[javascript]": {
Expand Down
129 changes: 108 additions & 21 deletions 3-JSKata/1-objects-and-arrays/kata.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,79 @@

// getGreeting should return a string containing
// 'Hello ' and the contents of `name`
function getGreeting(name) {}
function getGreeting(name) {
return 'Hello ' + name
}

// ageOneYear should return a new object with an `age` property 1 greater
// than the `age` property of `obj`
function ageOneYear(obj) {}
function ageOneYear(obj) {
console.log(obj)
let newObj = {
...obj,
age: obj['age'] + 1,
}
console.log(newObj)

return newObj
}
Comment on lines +13 to +22
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).


// makeObject should return an object that looks like this:
// (but using the arguments passed to the function)
// {
// key: value
// }
function makeObject(key, value) {}
function makeObject(key, value) {
return { [key]: value }
}

// getPropertyValue should return the value of the
// property contained in the `key` of `obj`
function getPropertyValue(obj, key) {}
function getPropertyValue(obj, key) {
return obj[key]
}

// addName should return a copy of `obj` with the addition of a `name`
// property that has the value of the `name` argument
// Tip: consider the object literal spread syntax
function addName(obj, name) {}
function addName(obj, name) {
let newObj = {
...obj,
name: name,
}
return newObj
}

// deleteProperty should return a new copy of `obj` without the property name
// that matches the `key` parameter
// Tip: consider JavaScript's `delete` operator
function deleteProperty(obj, key) {}
function deleteProperty(obj, key) {
let newObj = { ...obj }
delete newObj[key]
return newObj
}

// returnErrorIfFalsy should return a JavaScript Error object with message:
// 'Oh no, an error!'
// if val evaluates to false
// Tip: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
function returnErrorIfFalsy(val) {}
function returnErrorIfFalsy(val) {
if (val == false) {
return Error('Oh no, an error!')
}
}

// keys should return an array of the object's property names (keys)
// For example, given { foo: 1, bar: 2 } it would return ['foo', 'bar']
function getKeys(obj) {}
function getKeys(obj) {
return Object.keys(obj)
}

// getValues should return an array of the object's own values
// For example, given { foo: 1, bar: 2 } it would return [1, 2]
function getValues(obj) {}
function getValues(obj) {
return Object.values(obj)
}

/**
* Arrays
Expand All @@ -52,57 +85,111 @@ function getValues(obj) {}
// makeArrayOfItem should return an array that is `length` long, made up of
// `item`. For example, makeArrayOfItem('foo', 2) would return:
// ['foo', 'foo']
function makeArrayOfItem(item, length) {}
function makeArrayOfItem(item, length) {
return Array(length).fill(item)
}

// makeArrayOfItems should return an array containing all arguments passed to it
// Tip: consider JavaScript's Rest parameters
function makeArrayOfItems() {}
function makeArrayOfItems() {
return [...arguments]
}

// hasItem should return true if `item` is present in `arr` at least once,
// otherwise it should return false.
// Tip: there is an array function that makes this straightforward
function hasItem(arr, item) {}
function hasItem(arr, item) {
return arr.includes(item)
}

// getItemAtIndex should return arr[idx] but only if that index exists:
// if it doesn't, return a JavaScript Error object.
function getItemAtIndex(arr, idx) {}
function getItemAtIndex(arr, idx) {
if (arr[idx]) {
return arr[idx]
} else {
return Error()
}
}
Comment on lines +107 to +113
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).


// replaceItemAtIndex should return a copy of `arr` with
// the element at `idx` replaced with `item`
// Tip: consider the array literal spread syntax
function replaceItemAtIndex(arr, idx, item) {}
function replaceItemAtIndex(arr, idx, item) {
let newArr = [...arr]
newArr[idx] = item
return newArr
}

// insertItemAtIndex should return a copy of `arr` with `item` inserted at
// `idx` without overwriting any array values (the array should get longer)
function insertItemAtIndex(arr, item, idx) {}
function insertItemAtIndex(arr, item, idx) {
let newArr = [...arr]
newArr.splice(idx, 0, item)
return newArr
}

// deleteItemAtIndex should return a copy of `arr` without
// the element at `idx` (the array should get shorter).
function deleteItemAtIndex(arr, idx) {}
function deleteItemAtIndex(arr, idx) {
let newArr = [...arr]
newArr.splice(idx, 1)
return newArr
}

// deleteItem should return an array with every instance of `item` removed
function deleteItem(arr, item) {}
function deleteItem(arr, item) {
let newArr = []
for (const i in arr) {
if (arr[i] != item) {
newArr.push(arr[i])
}
}
return newArr
}

// zipObject should return an object built from two arrays
// For example, given ['foo', 'bar'] and [1, 2] it would return
// { foo: 1, bar: 2 }
function zipObject(keys, values) {}
function zipObject(keys, values) {
let newObj = {}
for (const i in keys) {
newObj[keys[i]] = values[i]
}
return newObj
}

// unzipObject should return an array of arrays, each one a pair of keys and values
// For example, given {foo: 1, bar: 2} it would return
// [['foo', 1], ['bar', 2]]
function unzipObject(obj) {}
function unzipObject(obj) {
return Object.entries(obj)
}

// findOneByProperty should return an object from `arr` that has the
// property AND value of `search`. For example, given:
// [{a: 1}, {b: 2, c: 3}] and {b: 2}
// it will return:
// {b: 2, c: 3}
function findOneByProperty(arr, search) {}
function findOneByProperty(arr, search) {
let key = Object.keys(search)[0]
let value = search[key]
return arr.find((obj) => obj[key] == value)
}

// findAll should return an array containing all objects in `arr` that
// have the property and value of `search`
function findAll(arr, search) {}
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
}
Comment on lines +182 to +192
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.


module.exports = {
addName,
Expand Down
56 changes: 45 additions & 11 deletions 3-JSKata/2-strings-and-numbers/utilities.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
function getType(thing) {}
function getType(thing) {
return typeof thing
}

function isNumber(thing) {}
function isNumber(thing) {
return typeof thing == 'number'
}

function toNumber(str) {}
function toNumber(str) {
return Number(str)
}

function isStringNumber(str) {}
function isStringNumber(str) {
return typeof str == 'string' && !isNaN(str)
}
Comment on lines +13 to +15
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()))).


function add(a, b) {}
function add(a, b) {
return a + b
}

function addStrings(a, b) {}
function addStrings(a, b) {
return String(Number(a) + Number(b))
}

function addStringsOrNumbers(a, b) {}
function addStringsOrNumbers(a, b) {
if (typeof a == 'number' && typeof b == 'number') {
return a + b
} else {
return String(Number(a) + Number(b))
}
}

function isEmail(str) {}
function isEmail(str) {
console.log
const emailRegex = /.+@.+\..+/
return emailRegex.test(str)
}
Comment on lines +33 to +37
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).


function countIf(array, fn) {}
function countIf(array, fn) {
count = 0
for (const item of array) {
if (fn(item)) {
count++
}
}
return count
}
Comment on lines +39 to +47
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix implicit global variable

count is implicitly global; declare it locally.

-function countIf(array, fn) {
-  count = 0
+function countIf(array, fn) {
+  let count = 0
   for (const item of array) {
-    if (fn(item)) {
-      count++
-    }
+    if (fn(item)) count++
   }
   return count
 }
📝 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 countIf(array, fn) {
count = 0
for (const item of array) {
if (fn(item)) {
count++
}
}
return count
}
function countIf(array, fn) {
let count = 0
for (const item of array) {
if (fn(item)) count++
}
return count
}
🤖 Prompt for AI Agents
In 3-JSKata/2-strings-and-numbers/utilities.js around lines 39 to 47, the
variable "count" is currently created as an implicit global; declare it locally
(e.g., use "let count = 0") at the start of the function to avoid polluting
global scope and ensure proper scoping, leaving the rest of the loop and return
logic unchanged.


function filterStringsWithCommas(str) {}
function filterStringsWithCommas(str) {
return str.includes(',')
}

function splitStringByCommas(str) {}
function splitStringByCommas(str) {
return str.split(',')
}

module.exports = {
getType,
Expand Down
5 changes: 4 additions & 1 deletion 3-JSKata/3-data-structures/find.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
function find(arr, searchDetails) {}
function find(arr, searchDetails) {
searchKey = Object.keys(searchDetails)[0]
return arr.find((obj) => obj[searchKey] == searchDetails[searchKey])
}
Comment on lines +1 to +4
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Fix implicit global and tighten comparisons; add basic input checks.

searchKey is assigned without let/const (creates a global). Also consider strict equality and guarding empty/invalid search details.

 function find(arr, searchDetails) {
-  searchKey = Object.keys(searchDetails)[0]
-  return arr.find((obj) => obj[searchKey] == searchDetails[searchKey])
+  if (!Array.isArray(arr) || !searchDetails || typeof searchDetails !== 'object') return undefined
+  const keys = Object.keys(searchDetails)
+  if (keys.length === 0) return undefined
+  const searchKey = keys[0]
+  return arr.find((obj) => obj && obj[searchKey] === searchDetails[searchKey])
 }
📝 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, searchDetails) {
searchKey = Object.keys(searchDetails)[0]
return arr.find((obj) => obj[searchKey] == searchDetails[searchKey])
}
function find(arr, searchDetails) {
if (!Array.isArray(arr) || !searchDetails || typeof searchDetails !== 'object') return undefined
const keys = Object.keys(searchDetails)
if (keys.length === 0) return undefined
const searchKey = keys[0]
return arr.find((obj) => obj && obj[searchKey] === searchDetails[searchKey])
}
🤖 Prompt for AI Agents
In 3-JSKata/3-data-structures/find.js around lines 1 to 4, the function creates
an implicit global (searchKey), uses loose equality, and lacks input validation;
fix by declaring searchKey with const (or let), add guards that arr is an array
and searchDetails is a non-null object with at least one own property, extract
the first key safely (e.g., const keys = Object.keys(searchDetails); if
(keys.length === 0) return undefined), and use strict equality (===) in the find
callback to compare obj[searchKey] to searchDetails[searchKey]; ensure the
function returns undefined for invalid inputs instead of throwing.


module.exports = find
8 changes: 7 additions & 1 deletion 3-JSKata/3-data-structures/getPropTypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
function getPropTypes(obj) {}
function getPropTypes(obj) {
let propTypes = []
for (const i in obj) {
propTypes.push(typeof obj[i])
}
return propTypes
}
Comment on lines +1 to +7
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid inherited props in results

for...in includes enumerable prototype props; use own keys and handle non-objects.

-function getPropTypes(obj) {
-  let propTypes = []
-  for (const i in obj) {
-    propTypes.push(typeof obj[i])
-  }
-  return propTypes
-}
+function getPropTypes(obj) {
+  if (obj === null || typeof obj !== 'object') return []
+  return Object.keys(obj).map((k) => typeof obj[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 getPropTypes(obj) {
let propTypes = []
for (const i in obj) {
propTypes.push(typeof obj[i])
}
return propTypes
}
function getPropTypes(obj) {
if (obj === null || typeof obj !== 'object') return []
return Object.keys(obj).map((k) => typeof obj[k])
}
🤖 Prompt for AI Agents
In 3-JSKata/3-data-structures/getPropTypes.js around lines 1 to 7, the function
uses for...in which includes enumerable prototype properties and doesn't guard
against non-objects; replace the loop with iteration over the object's own keys
(e.g., Object.keys or Object.getOwnPropertyNames) and add an early check that
the input is a non-null object (return [] or throw for invalid input), then push
typeof obj[key] for each own property so inherited props are excluded and
null/undefined inputs are handled.


module.exports = getPropTypes
4 changes: 3 additions & 1 deletion 3-JSKata/3-data-structures/getType.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
function getType(thing) {}
function getType(thing) {
return typeof thing
}

module.exports = getType
4 changes: 3 additions & 1 deletion 3-JSKata/3-data-structures/getValue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
function getValue(obj, key) {}
function getValue(obj, key) {
return obj[key]
}

module.exports = getValue
16 changes: 14 additions & 2 deletions 3-JSKata/3-data-structures/matrix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
function getMatrix(n) {}
function getMatrix(n) {
let newMatrix = []
for (let i = 0; i < n; i++) {
const row = Array(n).fill(0)
newMatrix.push(row)
}
return newMatrix
}

function updateMatrix(matrix, coords, value) {}
function updateMatrix(matrix, coords, value) {
const x = coords[0]
const y = coords[1]
matrix[x][y] = value
return matrix
}
Comment on lines +10 to +15
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.


module.exports = {
getMatrix,
Expand Down
8 changes: 6 additions & 2 deletions 3-JSKata/3-data-structures/positions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
function getFirst(arr) {}
function getFirst(arr) {
return arr[0]
}

function getLast(arr) {}
function getLast(arr) {
return arr[arr.length - 1]
}

module.exports = {
getFirst,
Expand Down
21 changes: 20 additions & 1 deletion 3-JSKata/3-data-structures/where.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
function where(arr, searchDetails) {}
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
}
Comment on lines +1 to +20
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.


module.exports = where
Loading