Skip to content

Conversation

@goofmint
Copy link
Owner

@goofmint goofmint commented Nov 21, 2025

Add problem data structure with 8 problems across 3 difficulty levels:

Level 1 (3 problems):

  • Variable redeclaration error
  • Infinite loop detection
  • Date.getMonth() misuse

Level 2 (3 problems):

  • Missing class method
  • Set/Map incorrect usage
  • String vs number type confusion

Level 3 (2 problems):

  • Object.entries with dot notation issue
  • Static vs instance method confusion with Array.find

Also implemented getProblems() function to dynamically load problems using Vite's import.meta.glob for efficient problem management.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added eight new JavaScript coding problems spanning three difficulty levels, featuring realistic bug-fixing scenarios including variable scope, infinite loops, date formatting, method chaining, data structure access, type conversion, dynamic property access, and class method design.
    • Enabled filtering and retrieval of problems by programming language and difficulty level for better problem discovery.

✏️ Tip: You can customize this high-level summary in your review settings.

Add problem data structure with 8 problems across 3 difficulty levels:

Level 1 (3 problems):
- Variable redeclaration error
- Infinite loop detection
- Date.getMonth() misuse

Level 2 (3 problems):
- Missing class method
- Set/Map incorrect usage
- String vs number type confusion

Level 3 (2 problems):
- Object.entries with dot notation issue
- Static vs instance method confusion with Array.find

Also implemented getProblems() function to dynamically load problems
using Vite's import.meta.glob for efficient problem management.
@coderabbitai
Copy link

coderabbitai bot commented Nov 21, 2025

Walkthrough

A problem-loading system is implemented via Vite glob imports with caching and filtering utilities in index.ts. Eight new JavaScript problem definitions are added across three difficulty levels, each documenting specific code bugs and design issues for learners to identify and fix.

Changes

Cohort / File(s) Change Summary
Problem Loader & Filtering
app/problems/index.ts
Introduces a problem-loading cache using Vite glob imports with initialization guard. Implements getProblems(lang, level) with filtering logic (replacing previous stub) and adds public getAllProblems() method to expose all loaded problem modules.
JavaScript Level 1 Problems
app/problems/javascript/level1/js-l1-001.json, js-l1-002.json, js-l1-003.json
Adds three problem definitions: variable redeclaration causing SyntaxError (js-l1-001), infinite loop due to missing loop variable decrement (js-l1-002), and incorrect month handling in date formatting via getMonth() (js-l1-003).
JavaScript Level 2 Problems
app/problems/javascript/level2/js-l2-001.json, js-l2-002.json, js-l2-003.json
Adds three problem definitions: missing method in method chaining (js-l2-001), Set index-access bug and function naming mismatch (js-l2-002), and type coercion issue with string input in arithmetic (js-l2-003).
JavaScript Level 3 Problems
app/problems/javascript/level3/js-l3-001.json, js-l3-002.json
Adds two problem definitions: incorrect dot notation vs. bracket notation for dynamic object property assignment (js-l3-001) and misuse of instance methods when static methods are required (js-l3-002).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • app/problems/index.ts: Review the Vite glob import usage, cache initialization guard logic, and filtering implementation in getProblems()
  • All problem JSON files: Validate structure consistency across all 8 problem definitions, verify issue descriptions are technically accurate and clearly identify the bugs/design concerns, and ensure metadata (ids, levels, languages) are correct and unique

Possibly related PRs

  • Complete basic setup configuration #2: Directly related—added type definitions and stubbed getProblems function; this PR implements the loader cache and filtering logic that builds upon those foundations.

Poem

🐰 A cache of bugs, so neatly bound,
Eight problems waiting to be found,
From syntax errors to type confusion,
Each level brings a new intrusion,
Now glob imports load them all with cheer!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing problem data for JavaScript across multiple levels. It directly aligns with the PR objectives of adding 8 problems organized by difficulty.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/implement-problem-data-019Ma8qCfZcS174YgvHza5Jr

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: 5

🧹 Nitpick comments (2)
app/problems/index.ts (2)

41-50: Add validation for loaded problem data.

The initialization function assumes all JSON files contain valid Problem objects. Consider adding basic validation or error handling to catch malformed data at load time rather than runtime.

 function initializeProblemsCache() {
   if (cacheInitialized) return;
 
   for (const path in problemModules) {
-    const problem = problemModules[path].default;
-    problemsCache.push(problem);
+    try {
+      const problem = problemModules[path].default;
+      // Basic validation
+      if (!problem.id || !problem.codeLanguage || !problem.level || !Array.isArray(problem.issues)) {
+        console.warn(`Invalid problem structure in ${path}:`, problem);
+        continue;
+      }
+      problemsCache.push(problem);
+    } catch (error) {
+      console.error(`Failed to load problem from ${path}:`, error);
+    }
   }
 
   cacheInitialized = true;
 }

58-66: Consider validating the level parameter.

The function accepts any number for level, but the problem set defines three levels (1, 2, 3). Invalid level values will silently return empty arrays, which might mask caller errors.

Add bounds checking or document the valid range:

 export function getProblems(lang: CodeLanguageOrAll, level: number): Problem[] {
   initializeProblemsCache();
+  
+  // Validate level is within expected bounds
+  if (level < 1 || level > 3) {
+    console.warn(`Invalid level ${level}, expected 1-3`);
+    return [];
+  }
 
   return problemsCache.filter((problem) => {
     const langMatch = lang === 'all' || problem.codeLanguage === lang;
     const levelMatch = problem.level === level;
     return langMatch && levelMatch;
   });
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44b6fa9 and c88ce51.

📒 Files selected for processing (9)
  • app/problems/index.ts (1 hunks)
  • app/problems/javascript/level1/js-l1-001.json (1 hunks)
  • app/problems/javascript/level1/js-l1-002.json (1 hunks)
  • app/problems/javascript/level1/js-l1-003.json (1 hunks)
  • app/problems/javascript/level2/js-l2-001.json (1 hunks)
  • app/problems/javascript/level2/js-l2-002.json (1 hunks)
  • app/problems/javascript/level2/js-l2-003.json (1 hunks)
  • app/problems/javascript/level3/js-l3-001.json (1 hunks)
  • app/problems/javascript/level3/js-l3-002.json (1 hunks)
🔇 Additional comments (8)
app/problems/javascript/level1/js-l1-001.json (1)

1-26: LGTM!

The problem definition is well-structured with accurate line references and clear bilingual descriptions. The issue correctly identifies the variable redeclaration bug.

app/problems/javascript/level1/js-l1-002.json (1)

1-27: LGTM!

The problem definition accurately captures the infinite loop bug. The line references span the entire while loop, which is appropriate for this issue context.

app/problems/javascript/level1/js-l1-003.json (1)

1-25: LGTM!

The problem clearly documents the getMonth() offset bug. Line references appropriately span both the buggy assignment and its usage, making the issue teaching-effective.

app/problems/javascript/level2/js-l2-002.json (1)

1-37: LGTM!

Both issues are well-defined with accurate line references. The critical bug (Set indexing) and design concern (misleading function name) are both appropriately documented.

app/problems/javascript/level2/js-l2-003.json (1)

1-41: LGTM!

Both issues are accurately referenced and well-documented. The type coercion problem and validation concern are appropriately categorized by severity.

app/problems/index.ts (3)

72-75: Good use of shallow copy to protect cache.

The spread operator prevents external mutation of the cache array. Note that the Problem objects themselves remain mutable. If strict immutability is required, consider documenting that callers should not modify returned objects, or investigate using a type-level readonly constraint.


83-95: LGTM!

The score calculation logic correctly implements the combo multiplier system with clear thresholds and proper integer rounding.


28-32: Hardcoded glob pattern is correct and no changes needed.

Verification confirms the glob pattern ./javascript/level*/*.json is intentionally JavaScript-only, which matches the actual directory structure. No other language directories exist. The code is well-designed: the Problem type already includes a codeLanguage field typed as CodeLanguage, and the getProblems() function properly filters by language. This creates a forward-compatible architecture where adding other languages (php, ruby, java, dart) only requires creating corresponding directories—no code changes would be needed. The current implementation is correct as-is.

Comment on lines +24 to +36
"issues": [
{
"id": "js-l2-001-1",
"lines": [17],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "subtractメソッドが定義されていないため、実行時にTypeErrorが発生します",
"en": "The 'subtract' method is not defined, causing a TypeError at runtime"
}
}
]
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Incorrect line reference for the missing method issue.

The issue describes that the subtract method is not defined, but the line reference points to line 17 (getValue() return statement). The actual problem occurs at line 22 where subtract() is called. Update the line reference to [22] to match the issue description.

     {
       "id": "js-l2-001-1",
-      "lines": [17],
+      "lines": [22],
       "type": "bug",
       "severity": "critical",
📝 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
"issues": [
{
"id": "js-l2-001-1",
"lines": [17],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "subtractメソッドが定義されていないため、実行時にTypeErrorが発生します",
"en": "The 'subtract' method is not defined, causing a TypeError at runtime"
}
}
]
"issues": [
{
"id": "js-l2-001-1",
"lines": [22],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "subtractメソッドが定義されていないため、実行時にTypeErrorが発生します",
"en": "The 'subtract' method is not defined, causing a TypeError at runtime"
}
}
]
🤖 Prompt for AI Agents
In app/problems/javascript/level2/js-l2-001.json around lines 24 to 36, the
issue entry "js-l2-001-1" incorrectly references line [17]; update its "lines"
array to [22] so the reported location matches the actual call to subtract() at
line 22. Edit the JSON so the "lines" field for that issue is [22] (no other
changes).

Comment on lines +22 to +31
{
"id": "js-l3-001-1",
"lines": [7],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "ドット記法でkeyを使うと文字列'key'がプロパティ名になります。ブラケット記法[key]を使う必要があります",
"en": "Using dot notation with 'key' creates a property named 'key'. Should use bracket notation [key]"
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Incorrect line reference for dot notation bug.

Issue js-l3-001-1 references line [7] (the closing brace }), but the actual bug is at line [6] where dot notation is used (currentSettings.key = value;). Update the line reference to match the buggy code line.

     {
       "id": "js-l3-001-1",
-      "lines": [7],
+      "lines": [6],
       "type": "bug",
📝 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
{
"id": "js-l3-001-1",
"lines": [7],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "ドット記法でkeyを使うと文字列'key'がプロパティ名になります。ブラケット記法[key]を使う必要があります",
"en": "Using dot notation with 'key' creates a property named 'key'. Should use bracket notation [key]"
}
{
"id": "js-l3-001-1",
"lines": [6],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "ドット記法でkeyを使うと文字列'key'がプロパティ名になります。ブラケット記法[key]を使う必要があります",
"en": "Using dot notation with 'key' creates a property named 'key'. Should use bracket notation [key]"
}
🤖 Prompt for AI Agents
In app/problems/javascript/level3/js-l3-001.json around lines 22 to 31, the rule
js-l3-001-1 incorrectly points to line [7] (closing brace) instead of the actual
buggy line; update the "lines" array for id "js-l3-001-1" from [7] to [6] so the
reference points to the line with the dot-notation usage (`currentSettings.key =
value;`).

Comment on lines +33 to +43
{
"id": "js-l3-001-2",
"lines": [4, 5, 6, 7, 8],
"type": "design",
"severity": "minor",
"score": 2,
"description": {
"ja": "for...ofループを使えばより簡潔に書けます: for (const [key, value] of entries)",
"en": "Can be written more concisely using for...of loop: for (const [key, value] of entries)"
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Incorrect line reference for design refactor issue.

Issue js-l3-001-2 references lines [4, 5, 6, 7, 8], but this includes the empty line at index 8. The for loop spans lines [3, 4, 5, 6, 7]. Update to accurately capture the loop block.

     {
       "id": "js-l3-001-2",
-      "lines": [4, 5, 6, 7, 8],
+      "lines": [3, 4, 5, 6, 7],
       "type": "design",
📝 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
{
"id": "js-l3-001-2",
"lines": [4, 5, 6, 7, 8],
"type": "design",
"severity": "minor",
"score": 2,
"description": {
"ja": "for...ofループを使えばより簡潔に書けます: for (const [key, value] of entries)",
"en": "Can be written more concisely using for...of loop: for (const [key, value] of entries)"
}
}
{
"id": "js-l3-001-2",
"lines": [3, 4, 5, 6, 7],
"type": "design",
"severity": "minor",
"score": 2,
"description": {
"ja": "for...ofループを使えばより簡潔に書けます: for (const [key, value] of entries)",
"en": "Can be written more concisely using for...of loop: for (const [key, value] of entries)"
}
}
🤖 Prompt for AI Agents
In app/problems/javascript/level3/js-l3-001.json around lines 33 to 43, the
issue entry js-l3-001-2 incorrectly lists the affected lines as [4, 5, 6, 7, 8]
(including an empty line); update the "lines" array to accurately reflect the
for loop block as [3, 4, 5, 6, 7] so the refactor suggestion references the
correct code span.

Comment on lines +29 to +40
"issues": [
{
"id": "js-l3-002-1",
"lines": [12],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "インスタンスメソッド内でthis.find()を呼んでいますが、thisはUserインスタンスで配列ではありません",
"en": "Calling this.find() in instance method, but 'this' is a User instance, not an array"
}
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Incorrect line reference for this.find() bug.

Issue js-l3-002-1 references line [12] (the closing brace of findByName), but the actual bug is at line [11] where this.find() is incorrectly called. Update to reference the correct line with the buggy code.

     {
       "id": "js-l3-002-1",
-      "lines": [12],
+      "lines": [11],
       "type": "bug",
🤖 Prompt for AI Agents
In app/problems/javascript/level3/js-l3-002.json around lines 29 to 40, the
issue js-l3-002-1 incorrectly points to line 12 (the closing brace) instead of
the actual buggy call at line 11; update the "lines" array for that issue from
[12] to [11] so the reported location points to the this.find() call inside
findByName.

Comment on lines +41 to +51
{
"id": "js-l3-002-2",
"lines": [22],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "findByNameはインスタンスメソッドですが、配列を受け取るように設計されていません。静的メソッドにすべきです",
"en": "findByName is an instance method but not designed to receive an array. Should be a static method"
}
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Out-of-bounds line reference.

Issue js-l3-002-2 references line [22], but the code array only contains 22 elements (indices 0-21). This line reference is out of bounds. The issue likely intends to reference the findByName method definition at lines [10, 11]. Update to the correct line range.

     {
       "id": "js-l3-002-2",
-      "lines": [22],
+      "lines": [10, 11],
       "type": "bug",
📝 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
{
"id": "js-l3-002-2",
"lines": [22],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "findByNameはインスタンスメソッドですが、配列を受け取るように設計されていません。静的メソッドにすべきです",
"en": "findByName is an instance method but not designed to receive an array. Should be a static method"
}
},
{
"id": "js-l3-002-2",
"lines": [10, 11],
"type": "bug",
"severity": "critical",
"score": 4,
"description": {
"ja": "findByNameはインスタンスメソッドですが、配列を受け取るように設計されていません。静的メソッドにすべきです",
"en": "findByName is an instance method but not designed to receive an array. Should be a static method"
}
},
🤖 Prompt for AI Agents
In app/problems/javascript/level3/js-l3-002.json around lines 41 to 51, the
issue entry "js-l3-002-2" incorrectly references line [22] (out of bounds);
update its "lines" field to point to the actual findByName method definition at
[10,11] so the JSON accurately references the method location.

@goofmint goofmint merged commit 62e9081 into main Nov 21, 2025
1 check passed
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.

3 participants