Explore
17 shards
REPO thoward37@gmail.com/shirt[create-new-file-named-slugify-js-exports] Create a new file named `slugify.js` that exports a function `slugify(s)`. The function should convert the input string `s` into a URL-friendly slug:
- Convert all characters to lower case.
- Replace spaces and consecutive whitespace with a single hyphen (`-`).
- Remove all characters that are not alphanumeric, hyphens, or underscores.
- Trim leading and trailing hyphens.
Add a test file `slugify.test.js` with at least three test cases:
1. Basic phrase conversion to lower‑case hyphenated slug.
2. Handling of special characters (e.g., punctuation) being removed.
3. Removal of leading/trailing whitespace and hyphens.
Use the project's testing framework and ensure all tests pass. REPO thoward37@gmail.com/shirt[create-new-file-named-truncate-js] Create a new file named `truncate.js` that exports a function `truncate(s, n)`. The function should take a string `s` and an integer `n`, and return a truncated version of the string:
- If `s` length is less than or equal to `n`, return `s` unchanged.
- If `s` length is greater than `n`, return the first `n` characters followed by an ellipsis (`...`).
Also create a corresponding test file `truncate.test.js` using the project's testing framework (e.g., Jest). Write at least three test cases:
1. String shorter than `n` returns unchanged.
2. String exactly `n` characters returns unchanged.
3. String longer than `n` returns truncated string with ellipsis.
Ensure the test imports the `truncate` function correctly and all tests pass. REPO thoward37@gmail.com/shirt[create-new-file-src-reverse-js-exports] Create a new file `src/reverse.js` that exports a function `reverse(s)` which returns the input string with its characters in reverse order. Handle edge cases such as empty strings and non-string inputs (throw a TypeError).
Add a corresponding test file `tests/reverse.test.js` using your project's testing framework. Write at least three test cases:
1. Normal string input (e.g., "world" → "dlrow").
2. Empty string input (should return an empty string).
3. Non-string input (e.g., null) should throw a TypeError.
Make sure the test imports the function correctly and all tests pass. No other code changes are required. REPO thoward37@gmail.com/shirt[create-new-file-src-capitalize-js] Create a new file `src/capitalize.js` that exports a function `capitalize(s)` which returns the input string with the first character converted to uppercase and the rest unchanged. Handle edge cases such as empty strings and non-string inputs (throw a TypeError).
Add a corresponding test file `tests/capitalize.test.js` using your project's testing framework (e.g., Jest, Mocha). Write at least three test cases:
1. Normal string input (e.g., "hello" → "Hello").
2. Empty string input (should return an empty string).
3. Non-string input (e.g., 123) should throw a TypeError.
Ensure the test imports the function correctly and all tests pass. No other code changes are required. REPO thoward37@gmail.com/shirt[create-new-file-named-lcm-js-appropriate] Create a new file named `lcm.js` (or appropriate language extension) that exports a function `lcm(a, b)` which returns the least common multiple of two integers `a` and `b`. The implementation should use the previously defined `gcd` logic (you may import it) and correctly handle zero and negative inputs. Provide a test file `lcm.test.js` (or appropriate test framework file) containing unit tests that cover normal cases, edge cases, and validation of behavior when inputs are zero or negative. Ensure the tests run independently with the project's testing configuration. REPO thoward37@gmail.com/shirt[create-new-file-named-isprime-js] Create a new file named `isPrime.js` (or appropriate language extension) that exports a function `isPrime(n)` which returns `true` if the integer `n` is a prime number and `false` otherwise. Implement an efficient algorithm that handles edge cases (e.g., non-positive integers, 1, 2). Additionally, add a corresponding test file `isPrime.test.js` (or appropriate test framework file) containing a comprehensive set of unit tests covering typical cases, edge cases, and invalid inputs. Ensure the tests can be run independently with the project's testing setup. REPO thoward37@gmail.com/shirt[create-new-file-named-gcd-js-appropriate] Create a new file named `gcd.js` (or appropriate language extension) that exports a function `gcd(a, b)` which returns the greatest common divisor of two integers `a` and `b` using Euclid's algorithm. The function should correctly handle negative numbers and zero. Add a matching test file `gcd.test.js` (or appropriate test framework file) with unit tests that verify correct results for a variety of input pairs, including edge cases such as one or both arguments being zero or negative. REPO thoward37@gmail.com/shirt[add-multiply-b-function-new-file] Add a multiply(a, b) function to a new file multiply.ts that returns a times b.
A Maintainer requested changes on the previous submission: needs unit tests alongside the implementation
The previous (rejected) draft, for reference -- revise it to address the feedback rather than starting over from scratch:
--- multiply.ts ---
/**
* Returns the product of two numbers.
*
* @param a - The first number.
* @param b - The second number.
* @returns The result of a multiplied by b.
*/
export function multiply(a: number, b: number): number {
return a * b;
}
3 shards
1 shard