Fix public access mode, introduce loading spinners, package fixes
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# Challenge: Inventory Stock Counter
|
||||
**Difficulty:** Easy
|
||||
**Language:** Java
|
||||
**Subject:** HashMap Fundamentals
|
||||
|
||||
## Description
|
||||
In software engineering, HashMaps are one of the most frequently used data structures for creating efficient lookups. One of the most common "real-world" applications for a HashMap is counting occurrences—such as counting how many times a specific word appears in a book, how many users performed an action, or, in this case, how many units of a product are in a warehouse.
|
||||
|
||||
Your task is to build a simple Inventory Management tool. You will be given an array of strings where each string represents a product being scanned into a warehouse. If a product is scanned multiple times, it means multiple units of that same product are being added to the stock. You need to process this list and produce a summary showing the total count for each unique product.
|
||||
|
||||
## Requirements
|
||||
- Create a method `Map<String, Integer> countStock(String[] products)` that accepts an array of product names.
|
||||
- Use a `HashMap<String, Integer>` to store the results, where the **Key** is the product name (String) and the **Value** is the total count (Integer).
|
||||
- The method must iterate through the array and update the counts correctly:
|
||||
- If a product is not in the map yet, add it with a count of 1.
|
||||
- If a product is already in the map, increment its existing count by 1.
|
||||
- The final Map should be returned by the method.
|
||||
|
||||
## Hints
|
||||
- Use the `map.containsKey(key)` method to check if a product has already been encountered.
|
||||
- Alternatively, look into the `map.getOrDefault(key, 0)` method, which is a very "clean" way to handle values that might not exist yet.
|
||||
- Ensure you import `java.util.HashMap` and `java.util.Map`.
|
||||
|
||||
## Validation
|
||||
- **Check:** Call `countStock(new String[]{"apple", "banana", "apple", "orange", "banana", "apple"})`
|
||||
- **Expected Output:** A Map containing: `{apple=3, banana=2, orange=1}`
|
||||
+235
-112
@@ -15,7 +15,9 @@ HANDBOOK_CATALOG: Dict[str, Dict[str, List[Dict[str, str]]]] = {
|
||||
{"id": "type_list", "title": "list", "desc": "Mutable ordered sequence collection type."},
|
||||
{"id": "type_dict", "title": "dict", "desc": "Key-value dictionary mapping collection type."},
|
||||
{"id": "type_set", "title": "set", "desc": "Unordered collection of unique items."},
|
||||
{"id": "type_tuple", "title": "tuple", "desc": "Immutable ordered sequence collection."},
|
||||
{"id": "print", "title": "print()", "desc": "Prints specified objects to standard output."},
|
||||
{"id": "input", "title": "input()", "desc": "Reads line from standard input as string."},
|
||||
{"id": "len", "title": "len()", "desc": "Returns the number of items in a container."},
|
||||
{"id": "range", "title": "range()", "desc": "Generates a sequence of numbers from start to stop."},
|
||||
{"id": "enumerate", "title": "enumerate()", "desc": "Yields index and value tuples from an iterable."},
|
||||
@@ -26,31 +28,192 @@ HANDBOOK_CATALOG: Dict[str, Dict[str, List[Dict[str, str]]]] = {
|
||||
{"id": "isinstance", "title": "isinstance()", "desc": "Checks if object is an instance of a class."},
|
||||
{"id": "type_func", "title": "type()", "desc": "Returns the type of an object."},
|
||||
{"id": "open", "title": "open()", "desc": "Opens a file and returns file object."},
|
||||
{"id": "input", "title": "input()", "desc": "Reads line from standard input as string."},
|
||||
{"id": "str_split", "title": "str.split()", "desc": "Splits string into list using delimiter."},
|
||||
{"id": "str_join", "title": "str.join()", "desc": "Concatenates string elements with separator."},
|
||||
{"id": "str_replace", "title": "str.replace()", "desc": "Replaces occurrences of substring."},
|
||||
{"id": "dict_get", "title": "dict.get()", "desc": "Returns value for key or default if missing."},
|
||||
{"id": "list_append", "title": "list.append()", "desc": "Appends item to end of list."},
|
||||
{"id": "sum", "title": "sum()", "desc": "Sums items of an iterable."},
|
||||
{"id": "min_max", "title": "min() / max()", "desc": "Returns smallest or largest item."},
|
||||
{"id": "abs", "title": "abs()", "desc": "Returns absolute value of number."},
|
||||
{"id": "round", "title": "round()", "desc": "Rounds float to given precision."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitive Types", "desc": "int, float, bool, str, and dynamic typing."},
|
||||
{"id": "control", "title": "Control Flow & Loops", "desc": "if, elif, else, for, while, break, continue."},
|
||||
{"id": "funcs", "title": "Functions & Type Hints", "desc": "def, return, lambda, *args, **kwargs."},
|
||||
{"id": "collections", "title": "Lists, Dicts & Sets", "desc": "Comprehensions, operations, set math."},
|
||||
{"id": "errors", "title": "Exception Handling", "desc": "try, except, else, finally, raise."},
|
||||
{"id": "oop", "title": "Classes & OOP", "desc": "class, __init__, self, inheritance."},
|
||||
{"id": "vars", "title": "Variables & Primitive Types", "desc": "int, float, bool, str, dynamic typing, mutability."},
|
||||
{"id": "control", "title": "Control Flow & Loops", "desc": "if, elif, else, for, while, break, continue, pass."},
|
||||
{"id": "funcs", "title": "Functions & Type Hints", "desc": "def, return, lambda, *args, **kwargs, docstrings."},
|
||||
{"id": "collections", "title": "Lists, Dicts, Sets & Tuples", "desc": "Comprehensions, operations, set math, tuple unpacking."},
|
||||
{"id": "errors", "title": "Exception Handling", "desc": "try, except, else, finally, raise, custom exceptions."},
|
||||
{"id": "oop", "title": "Classes & OOP Concepts", "desc": "class, __init__, self, inheritance, super(), dunder methods."},
|
||||
{"id": "modules", "title": "Modules & Standard Library", "desc": "import, math, sys, os, json, random, datetime."},
|
||||
{"id": "decorators", "title": "Decorators & Generators", "desc": "@decorator syntax, yield, generator expressions."},
|
||||
],
|
||||
},
|
||||
"java": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int / long", "desc": "32-bit and 64-bit primitive signed integer data types."},
|
||||
{"id": "type_boolean", "title": "boolean", "desc": "Primitive boolean data type (true or false)."},
|
||||
{"id": "type_double", "title": "float / double", "desc": "Single and double precision floating point types."},
|
||||
{"id": "type_char", "title": "char", "desc": "Single 16-bit Unicode character primitive."},
|
||||
{"id": "type_string", "title": "String", "desc": "Immutable sequence of characters in Java."},
|
||||
{"id": "sys_out", "title": "System.out.println()", "desc": "Prints text to standard output with newline."},
|
||||
{"id": "sys_print", "title": "System.out.print()", "desc": "Prints text to standard output without newline."},
|
||||
{"id": "scanner_next", "title": "Scanner.nextLine()", "desc": "Reads line of user input from System.in."},
|
||||
{"id": "str_length", "title": "String.length()", "desc": "Returns total character count of string."},
|
||||
{"id": "str_char_at", "title": "String.charAt()", "desc": "Returns character at specified 0-based index."},
|
||||
{"id": "str_substring", "title": "String.substring()", "desc": "Extracts substring between start and end index."},
|
||||
{"id": "str_equals", "title": "String.equals()", "desc": "Compares two strings for content equality."},
|
||||
{"id": "str_split", "title": "String.split()", "desc": "Splits string into array using regex delimiter."},
|
||||
{"id": "str_replace", "title": "String.replace()", "desc": "Replaces all target character sequences."},
|
||||
{"id": "math_abs", "title": "Math.abs()", "desc": "Returns absolute positive value of number."},
|
||||
{"id": "math_max", "title": "Math.max() / Math.min()", "desc": "Returns greater or lesser of two numerical values."},
|
||||
{"id": "math_pow", "title": "Math.pow()", "desc": "Raises base to exponent power (e.g. Math.pow(2, 3) = 8)."},
|
||||
{"id": "math_sqrt", "title": "Math.sqrt()", "desc": "Returns square root of a double value."},
|
||||
{"id": "math_random", "title": "Math.random()", "desc": "Returns pseudo-random double between 0.0 and 1.0."},
|
||||
{"id": "arrays_sort", "title": "Arrays.sort()", "desc": "Sorts primitive or object array in ascending order."},
|
||||
{"id": "list_add", "title": "List.add()", "desc": "Appends element to Java List collection."},
|
||||
{"id": "list_get", "title": "List.get()", "desc": "Returns element at specified index in List."},
|
||||
{"id": "list_size", "title": "List.size()", "desc": "Returns number of elements in collection."},
|
||||
{"id": "map_put", "title": "Map.put() / Map.get()", "desc": "Stores key-value pair or retrieves value by key in HashMap."},
|
||||
{"id": "set_add", "title": "Set.add()", "desc": "Adds element to HashSet if not already present."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitive Types", "desc": "int, double, boolean, String, char, float, final, scope."},
|
||||
{"id": "control", "title": "Control Flow & Loops", "desc": "if, else if, else, switch, for, for-each, while, do-while."},
|
||||
{"id": "arrays", "title": "Arrays & Collections", "desc": "1D/2D arrays, ArrayList, HashMap, HashSet, Iterators."},
|
||||
{"id": "methods", "title": "Methods & Overloading", "desc": "Signatures, return values, parameters, method overloading, static."},
|
||||
{"id": "classes", "title": "Classes & OOP Concepts", "desc": "Classes, objects, constructors, encapsulation, getters/setters."},
|
||||
{"id": "inheritance", "title": "Inheritance & Polymorphism", "desc": "extends, super, method overriding, @Override, dynamic dispatch."},
|
||||
{"id": "interfaces", "title": "Interfaces & Abstraction", "desc": "abstract class, abstract methods, interface, implements, default methods."},
|
||||
{"id": "exceptions", "title": "Exception Handling", "desc": "try, catch, finally, throw, throws, custom Exception classes."},
|
||||
{"id": "generics", "title": "Generics & Type Safety", "desc": "Generic classes, <T>, List<T>, bounded wildcards (? extends T)."},
|
||||
{"id": "packages", "title": "Packages & Access Modifiers", "desc": "package, import, public, private, protected, package-private."},
|
||||
],
|
||||
},
|
||||
"csharp": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int / long", "desc": "Signed 32-bit and 64-bit integer primitive types."},
|
||||
{"id": "type_bool", "title": "bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_float", "title": "float / double / decimal", "desc": "Single, double, and high-precision financial decimal types."},
|
||||
{"id": "type_string", "title": "string", "desc": "UTF-16 text string type in C#."},
|
||||
{"id": "console_write", "title": "Console.WriteLine()", "desc": "Writes line terminator to standard output."},
|
||||
{"id": "console_read", "title": "Console.ReadLine()", "desc": "Reads next line of characters from stdin."},
|
||||
{"id": "str_length", "title": "string.Length", "desc": "Gets number of characters in string."},
|
||||
{"id": "str_substr", "title": "string.Substring()", "desc": "Retrieves substring starting at index."},
|
||||
{"id": "str_split", "title": "string.Split()", "desc": "Splits string into array based on separator."},
|
||||
{"id": "str_replace", "title": "string.Replace()", "desc": "Replaces all occurrences of string/char."},
|
||||
{"id": "str_contains", "title": "string.Contains()", "desc": "Checks if string contains specified substring."},
|
||||
{"id": "math_abs", "title": "Math.Abs()", "desc": "Returns absolute value of number."},
|
||||
{"id": "math_max", "title": "Math.Max() / Math.Min()", "desc": "Returns larger or smaller of two values."},
|
||||
{"id": "math_pow", "title": "Math.Pow()", "desc": "Raises number to specified power."},
|
||||
{"id": "math_sqrt", "title": "Math.Sqrt()", "desc": "Returns square root of a number."},
|
||||
{"id": "rand_next", "title": "Random.Next()", "desc": "Generates random non-negative integer."},
|
||||
{"id": "list_add", "title": "List<T>.Add()", "desc": "Adds object to end of List<T>."},
|
||||
{"id": "list_remove", "title": "List<T>.Remove()", "desc": "Removes first occurrence of specific object."},
|
||||
{"id": "dict_add", "title": "Dictionary<K,V>[key]", "desc": "Key-value pair map accessor in C#."},
|
||||
{"id": "linq_where", "title": "LINQ (.Where(), .Select())", "desc": "Language Integrated Query operations on collections."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitive Types", "desc": "var, int, bool, string, double, decimal, const, readonly."},
|
||||
{"id": "control", "title": "Control Flow & Switches", "desc": "if, else, switch expressions, for, foreach, while, do while."},
|
||||
{"id": "methods", "title": "Methods & Parameters", "desc": "Methods, ref, out, in, optional parameters, extension methods."},
|
||||
{"id": "classes", "title": "Classes, Structs & Records", "desc": "class, struct, record, properties (get; set;), constructors."},
|
||||
{"id": "inheritance", "title": "Inheritance & Polymorphism", "desc": "virtual, override, sealed, base, abstract classes."},
|
||||
{"id": "interfaces", "title": "Interfaces & Abstraction", "desc": "interface, explicit implementation, default interface methods."},
|
||||
{"id": "generics", "title": "Generics & Collections", "desc": "List<T>, Dictionary<K,V>, HashSet<T>, generic constraints."},
|
||||
{"id": "linq", "title": "LINQ & Lambda Expressions", "desc": "Query syntax, method syntax, delegates, Func<T>, Action<T>."},
|
||||
{"id": "exceptions", "title": "Exception Handling", "desc": "try, catch, finally, throw, exception filters (when)."},
|
||||
],
|
||||
},
|
||||
"cpp": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int / long long", "desc": "Signed 32-bit and 64-bit integer primitive types."},
|
||||
{"id": "type_bool", "title": "bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_double", "title": "float / double", "desc": "Single or double precision floating point."},
|
||||
{"id": "type_string", "title": "std::string", "desc": "Standard library C++ string class."},
|
||||
{"id": "type_vector", "title": "std::vector<T>", "desc": "Dynamic array sequence container."},
|
||||
{"id": "std_cout", "title": "std::cout / std::cin", "desc": "Standard stream output and input operations."},
|
||||
{"id": "std_getline", "title": "std::getline()", "desc": "Reads line from input stream into string."},
|
||||
{"id": "vec_push_back", "title": "std::vector::push_back()", "desc": "Adds element to end of vector."},
|
||||
{"id": "std_sort", "title": "std::sort()", "desc": "Sorts range [first, last) in ascending order."},
|
||||
{"id": "make_unique", "title": "std::make_unique()", "desc": "Constructs std::unique_ptr object."},
|
||||
{"id": "make_shared", "title": "std::make_shared()", "desc": "Constructs std::shared_ptr object."},
|
||||
{"id": "math_abs", "title": "std::abs()", "desc": "Returns absolute value of number."},
|
||||
{"id": "math_max", "title": "std::max() / std::min()", "desc": "Returns maximum or minimum of two values."},
|
||||
{"id": "math_pow", "title": "std::pow() / std::sqrt()", "desc": "Calculates power or square root of double."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Primitive Data Types", "desc": "int, float, double, bool, char, void, const, constexpr, auto."},
|
||||
{"id": "control", "title": "Control Flow & Loops", "desc": "if, else, for, range-based for (auto& x : vec), while, switch."},
|
||||
{"id": "pointers", "title": "Pointers & References", "desc": "Raw pointers (*), references (&), nullptr, address-of (&)."},
|
||||
{"id": "memory", "title": "Smart Pointers & Memory", "desc": "unique_ptr, shared_ptr, weak_ptr, RAII pattern."},
|
||||
{"id": "classes", "title": "Classes & OOP", "desc": "class, struct, public, private, protected, constructors, destructors."},
|
||||
{"id": "inheritance", "title": "Inheritance & Virtual Functions", "desc": "Inheritance, virtual, override, pure virtual (= 0), abstract classes."},
|
||||
{"id": "templates", "title": "Templates & Generics", "desc": "Function templates, class templates, generic programming."},
|
||||
{"id": "stl", "title": "STL Containers & Iterators", "desc": "vector, map, set, unordered_map, pair, iterators (begin, end)."},
|
||||
{"id": "exceptions", "title": "Exception Handling", "desc": "try, catch, throw, std::exception, noexcept."},
|
||||
],
|
||||
},
|
||||
"javascript": {
|
||||
"functions": [
|
||||
{"id": "type_boolean", "title": "boolean", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_number", "title": "number", "desc": "IEEE 754 floating-point numerical type."},
|
||||
{"id": "type_string", "title": "string", "desc": "Textual string primitive data type."},
|
||||
{"id": "console_log", "title": "console.log()", "desc": "Outputs message to debugging console."},
|
||||
{"id": "fetch", "title": "fetch()", "desc": "Asynchronously fetches network resource via HTTP."},
|
||||
{"id": "arr_map", "title": "Array.prototype.map()", "desc": "Creates new array with mapped elements."},
|
||||
{"id": "arr_filter", "title": "Array.prototype.filter()", "desc": "Filters elements satisfying predicate function."},
|
||||
{"id": "arr_reduce", "title": "Array.prototype.reduce()", "desc": "Executes reducer function across elements."},
|
||||
{"id": "arr_includes", "title": "Array.prototype.includes()", "desc": "Determines whether array contains value."},
|
||||
{"id": "arr_push", "title": "Array.prototype.push() / pop()", "desc": "Appends or removes items from array end."},
|
||||
{"id": "obj_keys", "title": "Object.keys() / values()", "desc": "Returns array of object key names or values."},
|
||||
{"id": "json_parse", "title": "JSON.parse() / stringify()", "desc": "Parses JSON text or serializes object."},
|
||||
{"id": "math_max", "title": "Math.max() / Math.min()", "desc": "Returns largest or smallest of numbers."},
|
||||
{"id": "math_random", "title": "Math.random()", "desc": "Returns pseudo-random number between 0 and 1."},
|
||||
{"id": "str_includes", "title": "String.prototype.includes()", "desc": "Checks if string contains substring."},
|
||||
{"id": "str_split", "title": "String.prototype.split()", "desc": "Splits string into array using separator."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "const, let, var, number, string, boolean, null, undefined."},
|
||||
{"id": "control", "title": "Control Flow & Logic", "desc": "if, else, ternary (? :), switch, for, for...of, for...in, while."},
|
||||
{"id": "funcs", "title": "Arrow Functions & Scope", "desc": "function, => arrow syntax, closures, lexical this."},
|
||||
{"id": "objects", "title": "Objects & Prototypes", "desc": "Object literals, prototype inheritance, ES6 class syntax."},
|
||||
{"id": "async", "title": "Asynchronous JS & Promises", "desc": "Callbacks, Promise, async, await, event loop."},
|
||||
{"id": "modules", "title": "ES Modules (Import/Export)", "desc": "import, export default, named exports, CommonJS require."},
|
||||
{"id": "destructuring", "title": "Destructuring & Rest/Spread", "desc": "Array/Object destructuring, ...rest, ...spread operator."},
|
||||
],
|
||||
},
|
||||
"typescript": {
|
||||
"functions": [
|
||||
{"id": "type_boolean", "title": "boolean", "desc": "Boolean type annotation (true or false)."},
|
||||
{"id": "type_number", "title": "number", "desc": "Numerical primitive type annotation."},
|
||||
{"id": "type_string", "title": "string", "desc": "Textual string type annotation."},
|
||||
{"id": "type_any", "title": "any / unknown", "desc": "Escape hatch any or type-safe unknown."},
|
||||
{"id": "type_never", "title": "never / void", "desc": "Unreachable type or function returning nothing."},
|
||||
{"id": "partial", "title": "Partial<T>", "desc": "Constructs type with all properties optional."},
|
||||
{"id": "required", "title": "Required<T>", "desc": "Constructs type with all properties required."},
|
||||
{"id": "readonly", "title": "Readonly<T>", "desc": "Constructs type with all properties read-only."},
|
||||
{"id": "record", "title": "Record<K, V>", "desc": "Constructs object type with keys K and value V."},
|
||||
{"id": "pick", "title": "Pick<T, K> / Omit<T, K>", "desc": "Selects or removes subset of properties K from T."},
|
||||
{"id": "returntype", "title": "ReturnType<T>", "desc": "Extracts return type of function type T."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "types", "title": "Type Annotations & Primitives", "desc": "number, string, boolean, explicit typing, type inference."},
|
||||
{"id": "interfaces", "title": "Interfaces & Type Aliases", "desc": "interface vs type, extending interfaces, index signatures."},
|
||||
{"id": "unions", "title": "Unions & Type Narrowing", "desc": "type A | B, typeof, instanceof, custom type predicates (is)."},
|
||||
{"id": "generics", "title": "Generics & Constraints", "desc": "Generic functions (<T>), generic interfaces, extends constraints."},
|
||||
{"id": "enums", "title": "Enums & Literal Types", "desc": "enum, const enum, string/number literal union types."},
|
||||
{"id": "classes", "title": "Classes & Access Modifiers", "desc": "public, private, protected, readonly, abstract classes."},
|
||||
{"id": "decorators", "title": "Decorators & Utility Types", "desc": "Class/method decorators, built-in TS utility type library."},
|
||||
],
|
||||
},
|
||||
"rust": {
|
||||
"functions": [
|
||||
{"id": "type_bool", "title": "bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_i32", "title": "i32 / i64", "desc": "Signed integer types (32-bit or 64-bit)."},
|
||||
{"id": "type_u32", "title": "u32 / u64", "desc": "Unsigned integer types (32-bit or 64-bit)."},
|
||||
{"id": "type_f64", "title": "f32 / f64", "desc": "Floating-point primitive types."},
|
||||
{"id": "type_str", "title": "str / String", "desc": "String slice (&str) and owned String type."},
|
||||
{"id": "type_i32", "title": "i32 / i64", "desc": "Signed integer primitive types (32-bit or 64-bit)."},
|
||||
{"id": "type_u32", "title": "u32 / u64", "desc": "Unsigned integer primitive types (32-bit or 64-bit)."},
|
||||
{"id": "type_f64", "title": "f32 / f64", "desc": "Single and double precision floating-point types."},
|
||||
{"id": "type_str", "title": "str / String", "desc": "String slice (&str) and owned String buffer."},
|
||||
{"id": "type_vec", "title": "Vec<T>", "desc": "Growable heap-allocated vector collection."},
|
||||
{"id": "type_option", "title": "Option<T>", "desc": "Type representing optional value (Some or None)."},
|
||||
{"id": "type_result", "title": "Result<T, E>", "desc": "Type representing outcome (Ok or Err)."},
|
||||
@@ -65,132 +228,92 @@ HANDBOOK_CATALOG: Dict[str, Dict[str, List[Dict[str, str]]]] = {
|
||||
{"id": "box_new", "title": "Box::new()", "desc": "Allocates memory on heap."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "let, let mut, bool, i32, f64, char, str."},
|
||||
{"id": "ownership", "title": "Ownership & Borrowing", "desc": "Move semantics, references (&), mutable (&mut)."},
|
||||
{"id": "control", "title": "Control Flow & Match", "desc": "if, loop, while, for, match pattern matching."},
|
||||
{"id": "structs", "title": "Structs & Enums", "desc": "struct, impl, enum, Option, Result."},
|
||||
{"id": "traits", "title": "Traits & Generics", "desc": "trait definition, generic type signatures."},
|
||||
],
|
||||
},
|
||||
"cpp": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int", "desc": "Signed 32-bit integer primitive type."},
|
||||
{"id": "type_bool", "title": "bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_double", "title": "float / double", "desc": "Single or double precision floating point."},
|
||||
{"id": "type_string", "title": "std::string", "desc": "Standard library string object."},
|
||||
{"id": "type_vector", "title": "std::vector<T>", "desc": "Dynamic array sequence container."},
|
||||
{"id": "std_cout", "title": "std::cout / std::cin", "desc": "Standard input and output streams."},
|
||||
{"id": "vec_push_back", "title": "std::vector::push_back()", "desc": "Adds element to end of vector."},
|
||||
{"id": "std_sort", "title": "std::sort()", "desc": "Sorts range [first, last) in ascending order."},
|
||||
{"id": "make_unique", "title": "std::make_unique()", "desc": "Constructs unique pointer object."},
|
||||
{"id": "make_shared", "title": "std::make_shared()", "desc": "Constructs shared pointer object."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Primitive Data Types", "desc": "int, float, double, bool, char, void, const, auto."},
|
||||
{"id": "control", "title": "Control Flow & Loops", "desc": "if, else, for, while, do while, switch."},
|
||||
{"id": "pointers", "title": "Pointers & References", "desc": "Raw pointers (*), references (&), nullptr."},
|
||||
{"id": "classes", "title": "Classes & OOP", "desc": "class, struct, public, private, constructors."},
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "let, let mut, immutability, bool, i32, f64, char, str."},
|
||||
{"id": "ownership", "title": "Ownership, Borrowing & Lifetimes", "desc": "Move semantics, references (&), mutable (&mut), lifetime ('a)."},
|
||||
{"id": "control", "title": "Control Flow & Pattern Matching", "desc": "if, loop, while, for, match, if let, while let."},
|
||||
{"id": "structs", "title": "Structs & Implementations", "desc": "struct (field, tuple, unit), impl blocks, associated functions."},
|
||||
{"id": "enums", "title": "Enums & Option/Result", "desc": "enum, Option<T>, Result<T, E>, pattern matching."},
|
||||
{"id": "traits", "title": "Traits & Generics", "desc": "trait definition, impl Trait, generic functions, trait bounds."},
|
||||
{"id": "errors", "title": "Error Handling & Panic", "desc": "panic!(), recoverable errors with Result, ? operator."},
|
||||
{"id": "modules", "title": "Modules & Cargo Crates", "desc": "mod, use, pub, module hierarchy, Cargo dependencies."},
|
||||
],
|
||||
},
|
||||
"go": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int / int64", "desc": "Signed integer numerical primitive types."},
|
||||
{"id": "type_bool", "title": "bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_float", "title": "float64", "desc": "64-bit floating point real number type."},
|
||||
{"id": "type_string", "title": "string", "desc": "Immutable sequence of bytes / UTF-8 text."},
|
||||
{"id": "type_error", "title": "error", "desc": "Built-in interface type for error handling."},
|
||||
{"id": "fmt_println", "title": "fmt.Println() / Printf()", "desc": "Formatted write to standard output."},
|
||||
{"id": "make", "title": "make()", "desc": "Allocates and initializes slice, map, or chan."},
|
||||
{"id": "append", "title": "append()", "desc": "Appends elements to slice."},
|
||||
{"id": "make", "title": "make()", "desc": "Allocates and initializes slice, map, or channel."},
|
||||
{"id": "new", "title": "new()", "desc": "Allocates memory and returns pointer to zeroed value."},
|
||||
{"id": "append", "title": "append()", "desc": "Appends elements to end of slice."},
|
||||
{"id": "len", "title": "len() / cap()", "desc": "Returns length or capacity of collection."},
|
||||
{"id": "delete", "title": "delete()", "desc": "Deletes key entry from map."},
|
||||
{"id": "str_contains", "title": "strings.Contains()", "desc": "Reports whether substring is within string."},
|
||||
{"id": "str_atoi", "title": "strconv.Atoi()", "desc": "Converts string representation of integer to int."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "var, :=, int, float64, bool, string, const."},
|
||||
{"id": "control", "title": "Control Flow & Switch", "desc": "if with init, for loops, switch, select."},
|
||||
{"id": "structs", "title": "Structs & Interfaces", "desc": "type struct, methods, interface."},
|
||||
{"id": "goroutines", "title": "Goroutines & Channels", "desc": "go func(), chan, select statement."},
|
||||
],
|
||||
},
|
||||
"javascript": {
|
||||
"functions": [
|
||||
{"id": "type_boolean", "title": "boolean / bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_number", "title": "number", "desc": "IEEE 754 floating-point numerical type."},
|
||||
{"id": "type_string", "title": "string", "desc": "Textual string primitive data type."},
|
||||
{"id": "console_log", "title": "console.log()", "desc": "Outputs message to debugging console."},
|
||||
{"id": "arr_map", "title": "Array.prototype.map()", "desc": "Creates new array with mapped elements."},
|
||||
{"id": "arr_filter", "title": "Array.prototype.filter()", "desc": "Filters elements satisfying predicate."},
|
||||
{"id": "arr_reduce", "title": "Array.prototype.reduce()", "desc": "Executes reducer function on elements."},
|
||||
{"id": "obj_keys", "title": "Object.keys()", "desc": "Returns array of object key names."},
|
||||
{"id": "json_parse", "title": "JSON.parse()", "desc": "Parses JSON string into object."},
|
||||
{"id": "fetch", "title": "fetch()", "desc": "Asynchronously fetches network resource."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "const, let, var, number, string, boolean, null."},
|
||||
{"id": "control", "title": "Control Flow & Logic", "desc": "if, else, ternary, for...of, for...in."},
|
||||
{"id": "funcs", "title": "Arrow Functions & Async", "desc": "function, =>, async, await, Promises."},
|
||||
],
|
||||
},
|
||||
"typescript": {
|
||||
"functions": [
|
||||
{"id": "type_boolean", "title": "boolean / bool", "desc": "Boolean type annotation (true or false)."},
|
||||
{"id": "type_number", "title": "number / int", "desc": "Numerical primitive type annotation."},
|
||||
{"id": "type_string", "title": "string", "desc": "Textual string type annotation."},
|
||||
{"id": "type_any", "title": "any / unknown", "desc": "Escape hatch any or type-safe unknown."},
|
||||
{"id": "record", "title": "Record<K, V>", "desc": "Constructs object type with keys K and value V."},
|
||||
{"id": "partial", "title": "Partial<T>", "desc": "Constructs type with all properties optional."},
|
||||
{"id": "readonly", "title": "Readonly<T>", "desc": "Constructs type with all properties read-only."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "types", "title": "Type Annotations & Primitive Types", "desc": "number, string, boolean, interface, type."},
|
||||
{"id": "unions", "title": "Unions & Narrowing", "desc": "Type A | Type B, typeof, instanceof."},
|
||||
],
|
||||
},
|
||||
"java": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int / long", "desc": "Primitive integer data types."},
|
||||
{"id": "type_boolean", "title": "boolean / bool", "desc": "Primitive boolean true or false."},
|
||||
{"id": "type_double", "title": "float / double", "desc": "Primitive floating point data types."},
|
||||
{"id": "type_string", "title": "String", "desc": "Java String object class."},
|
||||
{"id": "sys_out", "title": "System.out.println()", "desc": "Writes formatted text to standard output."},
|
||||
{"id": "list_add", "title": "List.add()", "desc": "Appends element to Java List collection."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "int, double, boolean, String, char, float."},
|
||||
{"id": "control", "title": "Control Flow", "desc": "if, else, for, while, switch."},
|
||||
],
|
||||
},
|
||||
"csharp": {
|
||||
"functions": [
|
||||
{"id": "type_int", "title": "int / long", "desc": "Signed integer primitive types."},
|
||||
{"id": "type_bool", "title": "bool", "desc": "Boolean primitive type (true or false)."},
|
||||
{"id": "type_string", "title": "string", "desc": "UTF-16 text string type."},
|
||||
{"id": "console_write", "title": "Console.WriteLine()", "desc": "Writes line terminator to stdout."},
|
||||
{"id": "list_add", "title": "List<T>.Add()", "desc": "Adds item to List collection."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Types", "desc": "int, bool, string, double, float, var."},
|
||||
{"id": "control", "title": "Control Flow & OOP", "desc": "if, else, foreach, class, struct, record."},
|
||||
{"id": "vars", "title": "Variables & Primitives", "desc": "var, short declaration (:=), zero values, const, type cast."},
|
||||
{"id": "control", "title": "Control Flow & Switch", "desc": "if with init, for loops (single loop construct), switch."},
|
||||
{"id": "funcs", "title": "Functions & Multiple Returns", "desc": "func, multiple returns (val, err), variadic ...T, defer."},
|
||||
{"id": "pointers", "title": "Pointers & Addresses", "desc": "Pointer types (*T), address-of (&), dereferencing (*)."},
|
||||
{"id": "structs", "title": "Structs & Methods", "desc": "type Struct struct, value vs pointer receivers (s *Struct)."},
|
||||
{"id": "interfaces", "title": "Interfaces & Duck Typing", "desc": "type Interface interface, implicit satisfaction, interface{}/any."},
|
||||
{"id": "slices", "title": "Slices & Maps", "desc": "Slicing arrays arr[1:4], make(), map access (val, ok), range."},
|
||||
{"id": "concurrency", "title": "Goroutines & Channels", "desc": "go func(), buffered/unbuffered chan, select statement."},
|
||||
{"id": "errors", "title": "Error Handling", "desc": "Explicit error return (val, err), nil checks, custom error types."},
|
||||
],
|
||||
},
|
||||
"lua": {
|
||||
"functions": [
|
||||
{"id": "type_number", "title": "number / int", "desc": "Numerical data type."},
|
||||
{"id": "type_boolean", "title": "boolean / bool", "desc": "Boolean truth value (true or false)."},
|
||||
{"id": "type_string", "title": "string", "desc": "Byte sequence string type."},
|
||||
{"id": "type_number", "title": "number", "desc": "Numerical data type in Lua (float/int)."},
|
||||
{"id": "type_boolean", "title": "boolean", "desc": "Boolean truth value (true or false)."},
|
||||
{"id": "type_string", "title": "string", "desc": "Byte sequence string data type."},
|
||||
{"id": "type_table", "title": "table", "desc": "Universal associative array data structure."},
|
||||
{"id": "print", "title": "print()", "desc": "Prints values to standard output."},
|
||||
{"id": "type_func", "title": "type()", "desc": "Returns string name of value data type."},
|
||||
{"id": "tostring", "title": "tostring() / tonumber()", "desc": "Converts value to string or number."},
|
||||
{"id": "table_insert", "title": "table.insert() / remove()", "desc": "Inserts or removes element from array table."},
|
||||
{"id": "table_sort", "title": "table.sort()", "desc": "Sorts elements of array table in-place."},
|
||||
{"id": "pairs", "title": "pairs() / ipairs()", "desc": "Iterators for key-value or index-value table loops."},
|
||||
{"id": "str_len", "title": "string.len() / sub()", "desc": "Returns string length or substring slice."},
|
||||
{"id": "math_abs", "title": "math.abs() / random()", "desc": "Returns absolute value or pseudo-random float."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "vars", "title": "Variables & Types", "desc": "local, number, string, boolean, nil, table."},
|
||||
{"id": "vars", "title": "Variables & Scope", "desc": "local vs global, dynamic typing, nil, numbers, booleans, strings."},
|
||||
{"id": "control", "title": "Control Flow & Loops", "desc": "if, elseif, else, while, repeat...until, for (numeric/generic)."},
|
||||
{"id": "funcs", "title": "Functions & First-Class Functions", "desc": "function declaration, anonymous functions, multiple returns, ..."},
|
||||
{"id": "tables", "title": "Tables as Arrays & Dictionaries", "desc": "1-indexed arrays, key-value maps, nested tables."},
|
||||
{"id": "metatables", "title": "Metatables & OOP", "desc": "setmetatable(), __index, __newindex, OOP patterns in Lua."},
|
||||
{"id": "modules", "title": "Modules & Packages", "desc": "require(), returning module tables."},
|
||||
],
|
||||
},
|
||||
"html": {
|
||||
"functions": [
|
||||
{"id": "elem_doctype", "title": "<!DOCTYPE html>", "desc": "Declares document type as HTML5."},
|
||||
{"id": "elem_html", "title": "<html>", "desc": "Root element of HTML document."},
|
||||
{"id": "elem_body", "title": "<body>", "desc": "Container for all visible web page contents."},
|
||||
{"id": "elem_div", "title": "<div> / <span>", "desc": "Block or inline layout container elements."},
|
||||
{"id": "elem_doctype", "title": "<!DOCTYPE html>", "desc": "Declares document type as modern HTML5."},
|
||||
{"id": "elem_html", "title": "<html>", "desc": "Root element enclosing entire HTML document."},
|
||||
{"id": "elem_head", "title": "<head> / <title>", "desc": "Document metadata container and window title."},
|
||||
{"id": "elem_body", "title": "<body>", "desc": "Container for all visible web page content."},
|
||||
{"id": "elem_div", "title": "<div> / <span>", "desc": "Generic block-level and inline layout container elements."},
|
||||
{"id": "elem_headings", "title": "<h1> to <h6>", "desc": "Section heading tags ordered by hierarchy."},
|
||||
{"id": "elem_p", "title": "<p> / <br>", "desc": "Paragraph text block and line break elements."},
|
||||
{"id": "elem_a", "title": "<a>", "desc": "Anchor link element with href target attribute."},
|
||||
{"id": "elem_img", "title": "<img>", "desc": "Embedded image element with src and alt attributes."},
|
||||
{"id": "elem_lists", "title": "<ul> / <ol> / <li>", "desc": "Unordered bulleted or ordered numbered list items."},
|
||||
{"id": "elem_table", "title": "<table> / <tr> / <td>", "desc": "Tabular data container, table rows, and data cells."},
|
||||
{"id": "elem_form", "title": "<form>", "desc": "Interactive container for submitting user input controls."},
|
||||
{"id": "elem_input", "title": "<input>", "desc": "User input field (text, password, checkbox, radio, button)."},
|
||||
{"id": "elem_button", "title": "<button>", "desc": "Clickable action button element."},
|
||||
],
|
||||
"subjects": [
|
||||
{"id": "struct", "title": "Document Structure & Elements", "desc": "DOCTYPE, html, head, body, div, p, a, input."},
|
||||
{"id": "struct", "title": "Document Structure & Setup", "desc": "DOCTYPE, html, head, body, meta tags, UTF-8 charset."},
|
||||
{"id": "semantic", "title": "Semantic HTML5 Elements", "desc": "main, nav, header, footer, section, article, layout semantics."},
|
||||
{"id": "forms", "title": "Forms & User Input Controls", "desc": "form, input types, label, select, textarea, button, validation."},
|
||||
{"id": "links", "title": "Links & Media Embeds", "desc": "Anchor tags (href, target), img, video, audio, iframe, SVG."},
|
||||
{"id": "tables", "title": "Tables & Data Display", "desc": "table, thead, tbody, tr, th, td, colspan, rowspan."},
|
||||
{"id": "attributes", "title": "Attributes & Accessibility", "desc": "id, class, style, title, data-* attributes, ARIA roles."},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
+21
-11
@@ -5,7 +5,7 @@ from typing import List, Dict, Any
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Container, Horizontal, VerticalScroll
|
||||
from textual.widgets import Header, Footer, Static, OptionList, Button, Markdown, TextArea, Input
|
||||
from textual.widgets import Header, Footer, Static, OptionList, Button, Markdown, TextArea, Input, LoadingIndicator
|
||||
from textual.widgets.option_list import Option
|
||||
from textual.binding import Binding
|
||||
|
||||
@@ -230,6 +230,12 @@ class TactiTermTUI(App):
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#mentor-loading-indicator {
|
||||
display: none;
|
||||
height: 1fr;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
#mentor-input-title {
|
||||
height: 1;
|
||||
text-style: bold;
|
||||
@@ -331,6 +337,7 @@ class TactiTermTUI(App):
|
||||
yield Static("💡 Mentor", id="mentor-header")
|
||||
with VerticalScroll(id="mentor-response-scroll"):
|
||||
yield Markdown("Ask the mentor a question or click Check Answer...", id="mentor-response-display")
|
||||
yield LoadingIndicator(id="mentor-loading-indicator")
|
||||
|
||||
yield Static("Ask Question (Enter: Send | Shift+Enter: Newline):", id="mentor-input-title")
|
||||
yield MentorInputTextArea(id="mentor-question-input")
|
||||
@@ -550,9 +557,8 @@ class TactiTermTUI(App):
|
||||
main_box.add_class("sidebar-mentor-open")
|
||||
|
||||
q_input.text = ""
|
||||
self.query_one("#mentor-response-display", Markdown).update(
|
||||
"⏳ **Mentor is thinking and generating guidance...**\n\n*Analyzing your code, task requirements, and question...*"
|
||||
)
|
||||
self.query_one("#mentor-response-display", Markdown).display = False
|
||||
self.query_one("#mentor-loading-indicator", LoadingIndicator).display = True
|
||||
self.query_one("#status-bar", Static).update(
|
||||
f"⏳ Consulting Mentor at {mentor.config.llm_base_url}..."
|
||||
)
|
||||
@@ -583,9 +589,8 @@ class TactiTermTUI(App):
|
||||
"and give me feedback on my answer."
|
||||
)
|
||||
|
||||
self.query_one("#mentor-response-display", Markdown).update(
|
||||
"⏳ **Mentor is evaluating your solution against challenge requirements...**\n\n*Checking logic, requirements, and edge cases...*"
|
||||
)
|
||||
self.query_one("#mentor-response-display", Markdown).display = False
|
||||
self.query_one("#mentor-loading-indicator", LoadingIndicator).display = True
|
||||
self.query_one("#status-bar", Static).update("⏳ Consulting Mentor to check answer...")
|
||||
self.run_worker(self._mentor_worker(challenge, code, check_question))
|
||||
|
||||
@@ -752,12 +757,17 @@ class TactiTermTUI(App):
|
||||
self.load_challenges()
|
||||
|
||||
async def _mentor_worker(self, challenge: object, code: str, user_question: str) -> None:
|
||||
res = await mentor.get_guidance_async(challenge, code, user_question=user_question)
|
||||
response_text = res.get("mentor_response", "No response received.")
|
||||
try:
|
||||
res = await mentor.get_guidance_async(challenge, code, user_question=user_question)
|
||||
response_text = res.get("mentor_response", "No response received.")
|
||||
|
||||
q_header = f"### Question / Evaluation:\n> {user_question}\n\n---\n\n" if user_question else ""
|
||||
full_md = f"{q_header}{response_text}"
|
||||
q_header = f"### Question / Evaluation:\n> {user_question}\n\n---\n\n" if user_question else ""
|
||||
full_md = f"{q_header}{response_text}"
|
||||
except Exception as e:
|
||||
full_md = f"⚠️ Error consulting Mentor: {e}"
|
||||
|
||||
self.query_one("#mentor-loading-indicator", LoadingIndicator).display = False
|
||||
self.query_one("#mentor-response-display", Markdown).display = True
|
||||
self.query_one("#mentor-response-display", Markdown).update(full_md)
|
||||
self.query_one("#status-bar", Static).update("Mentor response received — Press F1 to ask or F2 to check answer")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user