diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0547c0cdcf..c5876fdc09 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,7 +1,16 @@ # Code owners .github/CODEOWNERS @exercism/maintainers-admin + +# The code sample shown in the code check when people sign up to Exercism +docs/SIGN_UP_SNIPPET.txt @exercism/maintainers-admin + .github/workflows @exercism/javascript +# The checks that must pass before a PR can merge, and the workflow that validates them. +# These lines must stay below .github/workflows, because the last matching line wins. +.github/required-checks.yml @exercism/maintainers-admin +.github/workflows/required-checks.yml @exercism/maintainers-admin + # Changes to `fetch-configlet` should be made in the `exercism/configlet` repo bin/fetch-configlet @exercism/maintainers-admin bin/fetch-configlet.ps1 @exercism/maintainers-admin diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b0c1effe76..024058129b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,23 +2,29 @@ version: 2 updates: # Keep dependencies for GitHub Actions up-to-date - - package-ecosystem: 'github-actions' - directory: '/' + - package-ecosystem: github-actions + directory: / schedule: - interval: 'monthly' + interval: monthly labels: - - 'dependencies :arrow_up_small:' - - 'github_actions' - - 'x:size/small' + - dependencies :arrow_up_small: + - github_actions + - x:size/small # Enable version updates for npm - - package-ecosystem: 'npm' + - package-ecosystem: npm # Look for `package.json` and `lock` files in the `root` directory - directory: '/' + directory: / # Check the npm registry for updates every day (weekdays) schedule: - interval: 'monthly' + interval: monthly labels: - - 'dependencies :arrow_up_small:' - - 'javascript' - - 'x:size/small' + - dependencies :arrow_up_small: + - javascript + - x:size/small + + # Enable updates to the dependencies of our Dockerfile + - package-ecosystem: docker + directory: / + schedule: + interval: monthly diff --git a/.github/labels.yml b/.github/labels.yml index 775388e833..3c75cb107a 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -167,6 +167,11 @@ description: "Work paused until further notice" color: "e4e669" +# This Exercism-wide label queues a PR's English for translation (see exercism/i18n) +- name: "ready-to-translate" + description: "The English in this PR is final; queue its translations" + color: "1d76db" + # ----------------------------------------------------------------------------------------- # # These are the repository-specific labels that augment the Exercise-wide labels defined in # # https://github.com/exercism/org-wide-files/blob/main/global-files/.github/labels.yml. # diff --git a/.github/required-checks.yml b/.github/required-checks.yml new file mode 100644 index 0000000000..cf24acfe3e --- /dev/null +++ b/.github/required-checks.yml @@ -0,0 +1,13 @@ +# These checks must pass before a PR can merge into main. +# Changes here will be automatically synced to the repo's ruleset. +# +# To remove or rename a check, first take it out of this file in its own PR and +# let that merge. Then remove or rename the job. If both happen in one PR, the PR +# will wait forever for a check that no longer runs. +checks: + - precheck + - verify + - configlet / configlet + - i18n / completeness + - Tests + - Validate required checks diff --git a/.github/workflows/action-format.yml b/.github/workflows/action-format.yml index df002f03e0..299cdc7664 100644 --- a/.github/workflows/action-format.yml +++ b/.github/workflows/action-format.yml @@ -65,7 +65,7 @@ jobs: run: corepack enable pnpm - name: Use Node.js LTS (22.x) - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 with: node-version: 22.x cache: 'pnpm' diff --git a/.github/workflows/ci.js.yml b/.github/workflows/ci.js.yml index 0b572c1613..2caade6864 100644 --- a/.github/workflows/ci.js.yml +++ b/.github/workflows/ci.js.yml @@ -13,14 +13,14 @@ jobs: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - name: Enable corepack to fix https://github.com/actions/setup-node/pull/901 run: corepack enable pnpm - - name: Use Node.js LTS (22.x) - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + - name: Use Node.js LTS (24.x) + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 with: - node-version: 22.x + node-version: 24.x cache: 'pnpm' - name: Install project dependencies @@ -34,15 +34,15 @@ jobs: strategy: matrix: - node-version: [22.x] + node-version: [24.x, 26.x] steps: - - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - name: Enable corepack to fix https://github.com/actions/setup-node/pull/901 run: corepack enable pnpm - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 with: node-version: ${{ matrix.node-version }} cache: 'pnpm' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d5b22faf94..15a2f49e76 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -29,11 +29,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v4 + uses: github/codeql-action/init@v4.39.1 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -44,7 +44,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v4 + uses: github/codeql-action/autobuild@v4.39.1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -58,4 +58,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v4 + uses: github/codeql-action/analyze@v4.39.1 diff --git a/.github/workflows/i18n-completeness.yml b/.github/workflows/i18n-completeness.yml new file mode 100644 index 0000000000..7a827c9d0f --- /dev/null +++ b/.github/workflows/i18n-completeness.yml @@ -0,0 +1,26 @@ +# This workflow is installed as .github/workflows/i18n-completeness.yml in +# every repo that holds English. Don't edit it in those repos. Edit it in +# exercism/i18n/source-repo-workflows/ and copy it to each repo. Keep the file +# name, because exercism/i18n's rerun-source-check.yml looks for it. +# +# This workflow checks that exercism/i18n has a translation of all the English +# a PR changes, and fails if anything is missing. The work happens in +# exercism/i18n/.github/workflows/source-completeness.yml. This file only sets +# when it runs and what it is allowed to do. +# +# GitHub reports this check as `i18n / completeness`. To make it a required +# check, require that name. + +name: i18n completeness + +on: + pull_request: + branches: [main] + +permissions: {} + +jobs: + i18n: + permissions: + contents: read + uses: exercism/i18n/.github/workflows/source-completeness.yml@main diff --git a/.github/workflows/i18n-queue.yml b/.github/workflows/i18n-queue.yml new file mode 100644 index 0000000000..0a54a99b87 --- /dev/null +++ b/.github/workflows/i18n-queue.yml @@ -0,0 +1,31 @@ +# This workflow is installed as .github/workflows/i18n-queue.yml in every repo +# that holds English. Don't edit it in those repos. Edit it in +# exercism/i18n/source-repo-workflows/ and copy it to each repo. +# +# When a maintainer adds the `ready-to-translate` label to a PR, this workflow +# opens an issue in exercism/i18n asking for the PR's English to be translated. +# The work happens in exercism/i18n/.github/workflows/source-queue.yml. This +# file only sets when it runs and what it is allowed to do. +# +# It runs on `pull_request_target` so that PRs from forks can use the +# organisation's secrets. That is safe because nothing in this workflow checks +# out or runs code from the PR. It only checks out exercism/i18n. +# `secrets: inherit` passes on the Exercism i18n app's private key, which the +# workflow uses to open the issue. + +name: i18n queue + +on: + pull_request_target: + types: [labeled, unlabeled, synchronize] + branches: [main] + +permissions: {} + +jobs: + i18n: + permissions: + contents: read + pull-requests: write + uses: exercism/i18n/.github/workflows/source-queue.yml@main + secrets: inherit diff --git a/.github/workflows/pr.ci.js.yml b/.github/workflows/pr.ci.js.yml index 39381f62fd..03ea5ee407 100644 --- a/.github/workflows/pr.ci.js.yml +++ b/.github/workflows/pr.ci.js.yml @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout PR - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} @@ -27,10 +27,10 @@ jobs: - name: Enable corepack to fix https://github.com/actions/setup-node/pull/901 run: corepack enable pnpm - - name: Use Node.js LTS (22.x) - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + - name: Use Node.js LTS (24.x) + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 with: - node-version: 22.x + node-version: 24.x cache: 'pnpm' - name: Install project dependencies @@ -44,11 +44,11 @@ jobs: strategy: matrix: - node-version: [22.x] + node-version: [24.x, 26.x] steps: - name: Checkout PR - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} @@ -65,7 +65,7 @@ jobs: run: corepack enable pnpm - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 with: node-version: ${{ matrix.node-version }} cache: 'pnpm' @@ -75,3 +75,18 @@ jobs: - name: Run exercism/javascript ci (runs tests) for changed/added exercises run: corepack pnpm node scripts/pr.mjs ${{ steps.changed-files.outputs.changed_files }} + + tests: + name: Tests + needs: ci + if: always() + runs-on: ubuntu-24.04 + steps: + - name: Check that every Node.js version passed + env: + RESULT: ${{ needs.ci.result }} + run: | + if [[ "$RESULT" != "success" ]]; then + echo "The exercise tests failed on at least one Node.js version." + exit 1 + fi diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml new file mode 100644 index 0000000000..e6db2f8519 --- /dev/null +++ b/.github/workflows/required-checks.yml @@ -0,0 +1,141 @@ +# Checks that all the checks listed in .github/required-checks.yml exist. +# Also fails if a PR removes a job that's still listed in main's copy of the file. +# +# It runs on every PR, so it can be listed as a required check itself. On a PR +# that changes neither the file nor a workflow, it passes straight away. + +name: Required checks + +on: + pull_request: + branches: [main] + +permissions: {} + +jobs: + validate: + name: Validate required checks + runs-on: ubuntu-24.04 + timeout-minutes: 45 + permissions: + checks: read + contents: read + pull-requests: read + steps: + - name: Check that every required check ran + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} + OWN_CHECK_NAME: Validate required checks + shell: ruby {0} + run: | + require "json" + require "open3" + require "yaml" + + GITHUB_ACTIONS_APP_ID = 15368 + REPO = ENV.fetch("REPO") + HEAD_SHA = ENV.fetch("HEAD_SHA") + OWN_CHECK_NAME = ENV.fetch("OWN_CHECK_NAME") + + def gh(*args) + output, error, status = Open3.capture3("gh", "api", *args) + [output, error, status] + end + + # Returns the file at a commit, or nil if the commit doesn't have one + def read_file(sha) + output, error, status = gh("repos/#{REPO}/contents/.github/required-checks.yml?ref=#{sha}", + "-H", "Accept: application/vnd.github.raw") + return nil if !status.success? && error.include?("HTTP 404") + abort "Reading .github/required-checks.yml at #{sha} failed: #{error}" unless status.success? + + output + end + + # Uses the same rules as scripts/sync-repo-settings in exercism/maintainers-admin-tools + def parse(yaml, where) + data = YAML.safe_load(yaml) + abort "#{where}: the file must have a `checks` list" unless data.is_a?(Hash) && data["checks"].is_a?(Array) + + data["checks"].map do |check| + check = { "name" => check } if check.is_a?(String) + abort "#{where}: each check must be a name or have a `name`: #{check.inspect}" unless check.is_a?(Hash) + + name = check["name"] + app = check.fetch("app", GITHUB_ACTIONS_APP_ID) + unless name.is_a?(String) && name.strip == name && !name.empty? && name.length <= 255 && !name.match?(/[[:cntrl:]]/) + abort "#{where}: not a valid check name: #{name.inspect}" + end + abort "#{where}: `app` must be a GitHub App id: #{app.inspect}" unless app.is_a?(Integer) && app.positive? + + [name, app] + end.uniq + rescue Psych::Exception => e + abort "#{where}: the file isn't valid YAML: #{e.message}" + end + + output, error, status = gh("--paginate", "repos/#{REPO}/pulls/#{ENV.fetch('PR_NUMBER')}/files", "--jq", ".[].filename") + abort "Reading this PR's changed files failed: #{error}" unless status.success? + + changed_files = output.lines(chomp: true) + unless changed_files.any? { |file| file == ".github/required-checks.yml" || file.start_with?(".github/workflows/") } + puts "This PR doesn't change .github/required-checks.yml or a workflow, so there's nothing to check." + exit + end + + head_yaml = read_file(HEAD_SHA) + base_yaml = read_file(ENV.fetch("BASE_SHA")) + wanted = head_yaml ? parse(head_yaml, "This PR's .github/required-checks.yml") : [] + on_main = base_yaml ? parse(base_yaml, "main's .github/required-checks.yml") : [] + + if wanted.empty? && on_main.empty? + puts "Neither this PR nor main lists any required checks." + exit + end + + # Wait for the PR's other checks to finish. Some checks start a little + # after this one, so wait at least 30 seconds, then check every 5 seconds. + # Stop only when two checks in a row find nothing running. + started = Time.now + quiet_polls = 0 + runs = [] + loop do + output, error, status = gh("--paginate", "--slurp", "repos/#{REPO}/commits/#{HEAD_SHA}/check-runs?per_page=100") + abort "Reading this PR's checks failed: #{error}" unless status.success? + + runs = JSON.parse(output).flat_map { |page| page["check_runs"] }.reject { |run| run["name"] == OWN_CHECK_NAME } + running = runs.reject { |run| run["status"] == "completed" } + quiet_polls = running.empty? ? quiet_polls + 1 : 0 + break if quiet_polls >= 2 && Time.now - started >= 30 + + puts "Waiting for: #{running.map { |run| run["name"] }.uniq.join(', ')}" unless running.empty? + sleep 5 + end + + ran = runs.map { |run| [run["name"], run.dig("app", "id")] }.uniq + problems = [] + + (wanted | on_main).each do |name, app| + # This check is running now, so it doesn't need to be found among the others + next if name == OWN_CHECK_NAME + next if ran.include?([name, app]) + + if on_main.include?([name, app]) + problems << "`#{name}` is still listed in main's .github/required-checks.yml, but it didn't run on this PR. " \ + "Remove it from the file in its own PR and merge that first. Then remove or rename the job." + else + problems << "`#{name}` is listed in .github/required-checks.yml, but it didn't run on this PR. " \ + "Make sure the name matches the check exactly, and that its workflow runs on every PR to main." + end + end + + if problems.any? + problems.each { |problem| puts "::error::#{problem}" } + exit 1 + end + + puts "All #{wanted.size} required checks ran on this PR." diff --git a/.github/workflows/verify-code-formatting.yml b/.github/workflows/verify-code-formatting.yml index 99c5b307e1..3e4471371b 100644 --- a/.github/workflows/verify-code-formatting.yml +++ b/.github/workflows/verify-code-formatting.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: 'Checkout code' - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - name: 'Verify formatting of all files' run: ./bin/check-formatting.sh diff --git a/concepts/type-checking/about.md b/concepts/type-checking/about.md index d855cc9dda..0afed179a3 100644 --- a/concepts/type-checking/about.md +++ b/concepts/type-checking/about.md @@ -74,7 +74,7 @@ The `Array` class has a method called `Array.isArray()` that checks if its argum While `instanceof Array` will not work with an array created in a different realm such as an `iframe` in a webpage, `Array.isArray()` will. -This is because the Array class has a different constructor in each realm, and each `iframe` has its own ream, meaning that the function in the prototype chain will be different, causing `instanceof Array` to fail. +This is because the Array class has a different constructor in each realm, and each `iframe` has its own realm, meaning that the function in the prototype chain will be different, causing `instanceof Array` to fail. `Array.isArray()` is capable of ignoring this, and should always be used when possible. It can also survive false positives where an object isn't actually an `Array`, and merely has `Array` in its prototype chain. diff --git a/concepts/type-checking/introduction.md b/concepts/type-checking/introduction.md index d855cc9dda..0afed179a3 100644 --- a/concepts/type-checking/introduction.md +++ b/concepts/type-checking/introduction.md @@ -74,7 +74,7 @@ The `Array` class has a method called `Array.isArray()` that checks if its argum While `instanceof Array` will not work with an array created in a different realm such as an `iframe` in a webpage, `Array.isArray()` will. -This is because the Array class has a different constructor in each realm, and each `iframe` has its own ream, meaning that the function in the prototype chain will be different, causing `instanceof Array` to fail. +This is because the Array class has a different constructor in each realm, and each `iframe` has its own realm, meaning that the function in the prototype chain will be different, causing `instanceof Array` to fail. `Array.isArray()` is capable of ignoring this, and should always be used when possible. It can also survive false positives where an object isn't actually an `Array`, and merely has `Array` in its prototype chain. diff --git a/config.json b/config.json index 0ac62ffcd5..b08f915e95 100644 --- a/config.json +++ b/config.json @@ -1447,7 +1447,12 @@ "name": "Rectangles", "uuid": "f8c6786e-bf93-4f35-b649-03f4e39bb094", "practices": [], - "prerequisites": [], + "prerequisites": [ + "arrays", + "loops", + "numbers", + "conditionals" + ], "difficulty": 4, "topics": [ "arrays", @@ -1736,6 +1741,14 @@ "text_formatting" ] }, + { + "slug": "sgf-parsing", + "name": "SGF Parsing", + "uuid": "6a44570c-f9a0-4cd7-9217-fcf7f39b3de0", + "practices": [], + "prerequisites": [], + "difficulty": 7 + }, { "slug": "diamond", "name": "Diamond", @@ -2011,7 +2024,13 @@ "name": "Bowling", "uuid": "dbf26ef1-62ff-4cb1-8ac7-09b022df3b2f", "practices": [], - "prerequisites": [], + "prerequisites": [ + "classes", + "arrays", + "conditionals", + "numbers", + "loops" + ], "difficulty": 8, "topics": [ "arrays", @@ -2028,7 +2047,11 @@ "name": "Strain", "uuid": "8407f9d5-7a7e-40c8-aace-a6a8294ae5e9", "practices": [], - "prerequisites": [], + "prerequisites": [ + "arrays", + "functions", + "array-transformations" + ], "difficulty": 4, "topics": [ "algorithms", @@ -2060,7 +2083,10 @@ "name": "Flatten Array", "uuid": "1a6c4a3b-d5db-4a5a-b123-66cf085defe6", "practices": [], - "prerequisites": [], + "prerequisites": [ + "arrays", + "recursion" + ], "difficulty": 5, "topics": [ "arrays", @@ -2072,7 +2098,10 @@ "name": "Nth Prime", "uuid": "7ce09989-f202-4c3c-8b7e-72cef18808c3", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "loops" + ], "difficulty": 5, "topics": [ "algorithms", @@ -2088,7 +2117,11 @@ "name": "Sieve", "uuid": "127287d1-ba44-4400-884a-6fe5f72e210f", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "arrays", + "loops" + ], "difficulty": 5, "topics": [ "conditionals", @@ -2103,7 +2136,11 @@ "name": "Rotational Cipher", "uuid": "34625b04-844e-41e3-b02b-3443b6b0b7cb", "practices": [], - "prerequisites": [], + "prerequisites": [ + "strings", + "numbers", + "conditionals" + ], "difficulty": 2, "topics": [ "conditionals", @@ -2117,7 +2154,12 @@ "name": "Diffie-Hellman", "uuid": "127eccbd-3009-4a8f-95c1-7d8aeb608550", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "arrays", + "loops", + "arithmetic-operators" + ], "difficulty": 3, "topics": [ "algorithms", @@ -2133,7 +2175,12 @@ "name": "Affine Cipher", "uuid": "37f26dda-6d5b-4b8a-a548-20758c5b6178", "practices": [], - "prerequisites": [], + "prerequisites": [ + "strings", + "numbers", + "arrays", + "loops" + ], "difficulty": 4, "topics": [ "algorithms", @@ -2147,7 +2194,11 @@ "name": "Atbash Cipher", "uuid": "a70e6027-eebe-43a1-84a6-763faa736169", "practices": [], - "prerequisites": [], + "prerequisites": [ + "strings", + "arrays", + "loops" + ], "difficulty": 7, "topics": [ "algorithms", @@ -2181,7 +2232,12 @@ "name": "Robot Simulator", "uuid": "5174bd15-eee2-4b53-b3ee-ca3a8c958a31", "practices": [], - "prerequisites": [], + "prerequisites": [ + "classes", + "strings", + "numbers", + "conditionals" + ], "difficulty": 5, "topics": [ "conditionals", @@ -2217,7 +2273,10 @@ "name": "Sum of Multiples", "uuid": "f7452f71-795b-40b6-847c-67ef4bb9db45", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "loops" + ], "difficulty": 5, "topics": [ "conditionals", @@ -2232,7 +2291,12 @@ "name": "Change", "uuid": "cfa5741c-9fe9-4cb5-a322-d77ba8145f4b", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "arrays", + "loops", + "algorithms" + ], "difficulty": 8, "topics": [ "algorithms", @@ -2254,7 +2318,11 @@ "name": "Protein Translation", "uuid": "775ae0ec-8db7-4568-a188-963931cf5ee1", "practices": [], - "prerequisites": [], + "prerequisites": [ + "strings", + "arrays", + "loops" + ], "difficulty": 1, "topics": [ "algorithms", @@ -2268,7 +2336,10 @@ "name": "Armstrong Numbers", "uuid": "b28c34f4-f7af-47db-95c6-f920e020bbba", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "loops" + ], "difficulty": 2, "topics": [ "algorithms", @@ -2325,7 +2396,12 @@ "name": "Roman Numerals", "uuid": "2fc4f834-a51c-42b8-a4d9-5263229e7648", "practices": [], - "prerequisites": [], + "prerequisites": [ + "strings", + "loops", + "numbers", + "conditionals" + ], "difficulty": 3, "topics": [ "conditionals", @@ -2391,7 +2467,10 @@ "name": "Square Root", "uuid": "31c7725e-def0-4dc9-88a0-e19afb9bfb06", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "arithmetic-operators" + ], "difficulty": 4, "topics": [ "bitwise_operations", @@ -2422,7 +2501,12 @@ "name": "All Your Base", "uuid": "d2d3cd13-b06c-4c24-9964-fb1554f70dd4", "practices": [], - "prerequisites": [], + "prerequisites": [ + "numbers", + "arrays", + "loops", + "arithmetic-operators" + ], "difficulty": 5, "topics": [ "conditionals", @@ -2465,7 +2549,11 @@ "name": "Queen Attack", "uuid": "007a4cd4-7324-4512-8905-ead0c78146f7", "practices": [], - "prerequisites": [], + "prerequisites": [ + "classes", + "numbers", + "conditionals" + ], "difficulty": 4, "topics": [ "conditionals", @@ -2482,7 +2570,12 @@ "name": "React", "uuid": "303c6969-9446-41aa-871a-11223a43e810", "practices": [], - "prerequisites": [], + "prerequisites": [ + "classes", + "numbers", + "arrays", + "functions" + ], "difficulty": 8, "topics": [ "algorithms", @@ -2495,7 +2588,13 @@ "name": "Zipper", "uuid": "fd1575f3-3087-4cfa-8a26-168fba6d0606", "practices": [], - "prerequisites": [], + "prerequisites": [ + "classes", + "recursion", + "trees", + "numbers", + "arrays" + ], "difficulty": 8, "topics": [ "recursion", @@ -2770,6 +2869,14 @@ "practices": [], "prerequisites": [], "difficulty": 2 + }, + { + "slug": "error-handling", + "name": "Error Handling", + "uuid": "de1c75f2-2461-4347-b5ca-b3cfaafe4d79", + "practices": [], + "prerequisites": [], + "difficulty": 4 } ] }, diff --git a/docs/SIGN_UP_SNIPPET.txt b/docs/SIGN_UP_SNIPPET.txt new file mode 100644 index 0000000000..6e04592fe6 --- /dev/null +++ b/docs/SIGN_UP_SNIPPET.txt @@ -0,0 +1,11 @@ +function mostCommonWord(text) { + const counts = {}; + let best = ""; + for (const word of text.toLowerCase().split(" ")) { + counts[word] = (counts[word] || 0) + 1; + if (counts[word] > (counts[best] || 0)) { + best = word; + } + } + return `"${best}" appears ${counts[best]} times`; +} diff --git a/exercises/concept/amusement-park/amusement-park.spec.js b/exercises/concept/amusement-park/amusement-park.spec.js index c25f8d9fc1..39d073ebd2 100644 --- a/exercises/concept/amusement-park/amusement-park.spec.js +++ b/exercises/concept/amusement-park/amusement-park.spec.js @@ -5,7 +5,7 @@ import { revokeTicket, simpleTicketStatus, ticketStatus, -} from './amusement-park'; +} from './amusement-park.js'; describe('createVisitor', () => { test('correctly assembles the visitor object', () => { diff --git a/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js b/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js index d373447db8..9ffc04cc5d 100644 --- a/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js +++ b/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js @@ -4,7 +4,7 @@ import { canFreePrisoner, canSignalPrisoner, canSpy, -} from './annalyns-infiltration'; +} from './annalyns-infiltration.js'; describe('can execute fast attack', () => { test('when the knight is awake', () => { diff --git a/exercises/concept/appointment-time/appointment-time.spec.js b/exercises/concept/appointment-time/appointment-time.spec.js index d0872cc2b3..1d23cd73bc 100644 --- a/exercises/concept/appointment-time/appointment-time.spec.js +++ b/exercises/concept/appointment-time/appointment-time.spec.js @@ -7,7 +7,7 @@ import { isValid, updateAppointment, timeBetween, -} from './appointment-time'; +} from './appointment-time.js'; describe('createAppointment', () => { test('uses the passed in current time', () => { diff --git a/exercises/concept/bird-watcher/bird-watcher.spec.js b/exercises/concept/bird-watcher/bird-watcher.spec.js index bbedf2210e..4ba8e7fa75 100644 --- a/exercises/concept/bird-watcher/bird-watcher.spec.js +++ b/exercises/concept/bird-watcher/bird-watcher.spec.js @@ -1,5 +1,9 @@ import { describe, expect, test } from '@jest/globals'; -import { birdsInWeek, fixBirdCountLog, totalBirdCount } from './bird-watcher'; +import { + birdsInWeek, + fixBirdCountLog, + totalBirdCount, +} from './bird-watcher.js'; const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom'); const customLogSymbol = Symbol.for('exercism.javascript.util.log'); diff --git a/exercises/concept/captains-log/captains-log.spec.js b/exercises/concept/captains-log/captains-log.spec.js index 5cfd79d0bb..fa9f8a8283 100644 --- a/exercises/concept/captains-log/captains-log.spec.js +++ b/exercises/concept/captains-log/captains-log.spec.js @@ -3,7 +3,7 @@ import { randomShipRegistryNumber, randomStardate, randomPlanetClass, -} from './captains-log'; +} from './captains-log.js'; describe('randomShipRegistryNumber', () => { test('registry numbers are valid', () => { diff --git a/exercises/concept/coordinate-transformation/coordinate-transformation.spec.js b/exercises/concept/coordinate-transformation/coordinate-transformation.spec.js index f548002ca0..53f99e7e5a 100644 --- a/exercises/concept/coordinate-transformation/coordinate-transformation.spec.js +++ b/exercises/concept/coordinate-transformation/coordinate-transformation.spec.js @@ -4,7 +4,7 @@ import { memoizeTransform, scale2d, translate2d, -} from './coordinate-transformation'; +} from './coordinate-transformation.js'; const fakeTransform = () => { let first = true; diff --git a/exercises/concept/custom-signs/custom-signs.spec.js b/exercises/concept/custom-signs/custom-signs.spec.js index 3c805c909e..447e064f06 100644 --- a/exercises/concept/custom-signs/custom-signs.spec.js +++ b/exercises/concept/custom-signs/custom-signs.spec.js @@ -4,7 +4,7 @@ import { buildSign, costOf, graduationFor, -} from './custom-signs'; +} from './custom-signs.js'; describe('buildSign', () => { test('occasion is Birthday', () => { diff --git a/exercises/concept/elyses-analytic-enchantments/enchantments.spec.js b/exercises/concept/elyses-analytic-enchantments/enchantments.spec.js index 31e9ee1aae..dcea035630 100644 --- a/exercises/concept/elyses-analytic-enchantments/enchantments.spec.js +++ b/exercises/concept/elyses-analytic-enchantments/enchantments.spec.js @@ -6,7 +6,7 @@ import { getFirstEvenCardPosition, getFirstOddCard, isEachCardEven, -} from './enchantments'; +} from './enchantments.js'; describe('getCardPosition', () => { test('when it is the first card', () => { diff --git a/exercises/concept/elyses-destructured-enchantments/enchantments.spec.js b/exercises/concept/elyses-destructured-enchantments/enchantments.spec.js index c4d15a9ae3..a1f19dbbc3 100644 --- a/exercises/concept/elyses-destructured-enchantments/enchantments.spec.js +++ b/exercises/concept/elyses-destructured-enchantments/enchantments.spec.js @@ -6,7 +6,7 @@ import { shiftThreeCardsAround, pickNamedPile, swapNamedPile, -} from './enchantments'; +} from './enchantments.js'; const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom'); const customLogSymbol = Symbol.for('exercism.javascript.util.log'); diff --git a/exercises/concept/elyses-enchantments/enchantments.spec.js b/exercises/concept/elyses-enchantments/enchantments.spec.js index 15cdf6e5b7..67095f8ba6 100644 --- a/exercises/concept/elyses-enchantments/enchantments.spec.js +++ b/exercises/concept/elyses-enchantments/enchantments.spec.js @@ -8,7 +8,7 @@ import { removeItemAtBottom, removeItemFromTop, setItem, -} from './enchantments'; +} from './enchantments.js'; describe('pick a card', () => { test('get the first card', () => { diff --git a/exercises/concept/elyses-looping-enchantments/enchantments.spec.js b/exercises/concept/elyses-looping-enchantments/enchantments.spec.js index 3009f52f79..54ded51aa4 100644 --- a/exercises/concept/elyses-looping-enchantments/enchantments.spec.js +++ b/exercises/concept/elyses-looping-enchantments/enchantments.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { cardTypeCheck, determineOddEvenCards } from './enchantments'; +import { cardTypeCheck, determineOddEvenCards } from './enchantments.js'; const TYPE_IS_ODD = false; const TYPE_IS_EVEN = true; diff --git a/exercises/concept/elyses-transformative-enchantments/enchantments.spec.js b/exercises/concept/elyses-transformative-enchantments/enchantments.spec.js index 0b10805fa7..87346347c5 100644 --- a/exercises/concept/elyses-transformative-enchantments/enchantments.spec.js +++ b/exercises/concept/elyses-transformative-enchantments/enchantments.spec.js @@ -7,7 +7,7 @@ import { seeingDouble, threeOfEachThree, twoIsSpecial, -} from './enchantments'; +} from './enchantments.js'; describe('seeingDouble', () => { test('doubles all the values', () => { diff --git a/exercises/concept/factory-sensors/factory-sensors.spec.js b/exercises/concept/factory-sensors/factory-sensors.spec.js index 5ecbd96202..427ca920c2 100644 --- a/exercises/concept/factory-sensors/factory-sensors.spec.js +++ b/exercises/concept/factory-sensors/factory-sensors.spec.js @@ -5,7 +5,7 @@ import { monitorTheMachine, OverheatingError, reportOverheating, -} from './factory-sensors'; +} from './factory-sensors.js'; describe('checkHumidityLevel', () => { test('should throw if the humidity percentage is 71', () => { diff --git a/exercises/concept/freelancer-rates/freelancer-rates.spec.js b/exercises/concept/freelancer-rates/freelancer-rates.spec.js index 9c8a3d5e60..e6e825a667 100644 --- a/exercises/concept/freelancer-rates/freelancer-rates.spec.js +++ b/exercises/concept/freelancer-rates/freelancer-rates.spec.js @@ -3,7 +3,7 @@ import { dayRate, daysInBudget, priceWithMonthlyDiscount, -} from './freelancer-rates'; +} from './freelancer-rates.js'; const DIFFERENCE_PRECISION_IN_DIGITS = 6; diff --git a/exercises/concept/fruit-picker/.meta/exemplar.js b/exercises/concept/fruit-picker/.meta/exemplar.js index dba3e028eb..f4ac574a46 100644 --- a/exercises/concept/fruit-picker/.meta/exemplar.js +++ b/exercises/concept/fruit-picker/.meta/exemplar.js @@ -2,8 +2,8 @@ // // @ts-check -import { notify } from './notifier'; -import { order } from './grocer'; +import { notify } from './notifier.js'; +import { order } from './grocer.js'; /** * @return void diff --git a/exercises/concept/fruit-picker/fruit-picker.js b/exercises/concept/fruit-picker/fruit-picker.js index 2390e6c336..65124ab6e8 100644 --- a/exercises/concept/fruit-picker/fruit-picker.js +++ b/exercises/concept/fruit-picker/fruit-picker.js @@ -9,8 +9,8 @@ // // In your own projects, files, and code, you can play with @ts-check as well. -import { notify } from './notifier'; -import { order } from './grocer'; +import { notify } from './notifier.js'; +import { order } from './grocer.js'; /** * @return void diff --git a/exercises/concept/fruit-picker/fruit-picker.spec.js b/exercises/concept/fruit-picker/fruit-picker.spec.js index 3e1a59bdfd..9487d8898f 100644 --- a/exercises/concept/fruit-picker/fruit-picker.spec.js +++ b/exercises/concept/fruit-picker/fruit-picker.spec.js @@ -1,13 +1,18 @@ import { afterEach, describe, expect, test, jest } from '@jest/globals'; -import { onError, onSuccess, orderFromGrocer, postOrder } from './fruit-picker'; -import { order } from './grocer'; -import { notify } from './notifier'; - -jest.mock('./notifier', () => ({ +import { + onError, + onSuccess, + orderFromGrocer, + postOrder, +} from './fruit-picker.js'; +import { order } from './grocer.js'; +import { notify } from './notifier.js'; + +jest.mock('./notifier.js', () => ({ notify: jest.fn(), })); -jest.mock('./grocer', () => ({ +jest.mock('./grocer.js', () => ({ order: jest.fn(), })); diff --git a/exercises/concept/high-score-board/high-score-board.spec.js b/exercises/concept/high-score-board/high-score-board.spec.js index 42f5f67823..9361d4d168 100644 --- a/exercises/concept/high-score-board/high-score-board.spec.js +++ b/exercises/concept/high-score-board/high-score-board.spec.js @@ -5,7 +5,7 @@ import { createScoreBoard, removePlayer, updateScore, -} from './high-score-board'; +} from './high-score-board.js'; describe('createScoreBoard', () => { test('creates a new board with a test entry', () => { diff --git a/exercises/concept/lasagna-master/lasagna-master.spec.js b/exercises/concept/lasagna-master/lasagna-master.spec.js index 573007d474..a10a5a4855 100644 --- a/exercises/concept/lasagna-master/lasagna-master.spec.js +++ b/exercises/concept/lasagna-master/lasagna-master.spec.js @@ -5,7 +5,7 @@ import { preparationTime, quantities, scaleRecipe, -} from './lasagna-master'; +} from './lasagna-master.js'; const DIFFERENCE_PRECISION_IN_DIGITS = 6; diff --git a/exercises/concept/lasagna/lasagna.spec.js b/exercises/concept/lasagna/lasagna.spec.js index 243ecf64c0..ee90d90db9 100644 --- a/exercises/concept/lasagna/lasagna.spec.js +++ b/exercises/concept/lasagna/lasagna.spec.js @@ -4,7 +4,7 @@ import { preparationTimeInMinutes, remainingMinutesInOven, totalTimeInMinutes, -} from './lasagna'; +} from './lasagna.js'; describe('EXPECTED_MINUTES_IN_OVEN', () => { test('constant is defined correctly', () => { diff --git a/exercises/concept/lucky-numbers/lucky-numbers.spec.js b/exercises/concept/lucky-numbers/lucky-numbers.spec.js index 098c881f06..33a5fd7817 100644 --- a/exercises/concept/lucky-numbers/lucky-numbers.spec.js +++ b/exercises/concept/lucky-numbers/lucky-numbers.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { errorMessage, luckyNumber, twoSum } from './lucky-numbers'; +import { errorMessage, luckyNumber, twoSum } from './lucky-numbers.js'; describe('twoSum', () => { test('sums the numbers correctly for short arrays', () => { diff --git a/exercises/concept/mixed-juices/mixed-juices.spec.js b/exercises/concept/mixed-juices/mixed-juices.spec.js index 64eeea52c1..ba49933ad6 100644 --- a/exercises/concept/mixed-juices/mixed-juices.spec.js +++ b/exercises/concept/mixed-juices/mixed-juices.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { limesToCut, remainingOrders, timeToMixJuice } from './mixed-juices'; +import { limesToCut, remainingOrders, timeToMixJuice } from './mixed-juices.js'; describe('timeToMixJuice', () => { test("returns the correct time for 'Pure Strawberry Joy'", () => { diff --git a/exercises/concept/nullability/nullability.spec.js b/exercises/concept/nullability/nullability.spec.js index 95944bb5e3..2bed56f07a 100644 --- a/exercises/concept/nullability/nullability.spec.js +++ b/exercises/concept/nullability/nullability.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { printBadge } from './nullability'; +import { printBadge } from './nullability.js'; describe('nullability', () => { describe('printBadge', () => { diff --git a/exercises/concept/ozans-playlist/ozans-playlist.spec.js b/exercises/concept/ozans-playlist/ozans-playlist.spec.js index 5047bd1618..e800876b0d 100644 --- a/exercises/concept/ozans-playlist/ozans-playlist.spec.js +++ b/exercises/concept/ozans-playlist/ozans-playlist.spec.js @@ -5,7 +5,7 @@ import { hasTrack, listArtists, removeDuplicates, -} from './ozans-playlist'; +} from './ozans-playlist.js'; describe('removeDuplicates', () => { test('works for an empty playlist', () => { diff --git a/exercises/concept/pizza-order/pizza-order.spec.js b/exercises/concept/pizza-order/pizza-order.spec.js index 58c7677028..19d5cc90d2 100644 --- a/exercises/concept/pizza-order/pizza-order.spec.js +++ b/exercises/concept/pizza-order/pizza-order.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { orderPrice, pizzaPrice } from './pizza-order'; +import { orderPrice, pizzaPrice } from './pizza-order.js'; class PizzaOrder { /** diff --git a/exercises/concept/poetry-club-door-policy/door-policy.spec.js b/exercises/concept/poetry-club-door-policy/door-policy.spec.js index 3847542712..33b08b6fb1 100644 --- a/exercises/concept/poetry-club-door-policy/door-policy.spec.js +++ b/exercises/concept/poetry-club-door-policy/door-policy.spec.js @@ -4,7 +4,7 @@ import { backDoorResponse, frontDoorPassword, frontDoorResponse, -} from './door-policy'; +} from './door-policy.js'; const recite = (poem, responseFn) => { return poem.map((line) => responseFn(line)); diff --git a/exercises/concept/recycling-robot/.docs/introduction.md b/exercises/concept/recycling-robot/.docs/introduction.md index 21f826324b..8628305814 100644 --- a/exercises/concept/recycling-robot/.docs/introduction.md +++ b/exercises/concept/recycling-robot/.docs/introduction.md @@ -74,7 +74,7 @@ The `Array` class has a method called `Array.isArray()` that checks if its argum While `instanceof Array` will not work with an array created in a different realm such as an `iframe` in a webpage, `Array.isArray()` will. -This is because the Array class has a different constructor in each realm, and each `iframe` has its own ream, meaning that the function in the prototype chain will be different, causing `instanceof Array` to fail. +This is because the Array class has a different constructor in each realm, and each `iframe` has its own realm, meaning that the function in the prototype chain will be different, causing `instanceof Array` to fail. `Array.isArray()` is capable of ignoring this, and should always be used when possible. It can also survive false positives where an object isn't actually an `Array`, and merely has `Array` in its prototype chain. diff --git a/exercises/concept/recycling-robot/assembly-line.spec.js b/exercises/concept/recycling-robot/assembly-line.spec.js index d338348dff..286a342750 100644 --- a/exercises/concept/recycling-robot/assembly-line.spec.js +++ b/exercises/concept/recycling-robot/assembly-line.spec.js @@ -11,7 +11,7 @@ import { hasType, hasIdProperty, hasDefinedType, -} from './assembly-line'; +} from './assembly-line.js'; import { ElectronicDevice } from './lib.js'; describe('isBoolean', () => { diff --git a/exercises/concept/regular-chatbot/regular-chatbot.spec.js b/exercises/concept/regular-chatbot/regular-chatbot.spec.js index 4d409d72aa..0a3eab911f 100644 --- a/exercises/concept/regular-chatbot/regular-chatbot.spec.js +++ b/exercises/concept/regular-chatbot/regular-chatbot.spec.js @@ -5,7 +5,7 @@ import { isValidCommand, niceToMeetYou, removeEmoji, -} from './regular-chatbot'; +} from './regular-chatbot.js'; describe('isValidCommand', () => { test('recognizes wheter the command is at the first position', () => { diff --git a/exercises/concept/train-driver/train-driver.spec.js b/exercises/concept/train-driver/train-driver.spec.js index 87f7a321fb..3faa989e0f 100644 --- a/exercises/concept/train-driver/train-driver.spec.js +++ b/exercises/concept/train-driver/train-driver.spec.js @@ -6,7 +6,7 @@ import { correctListOfWagons, extendRouteInformation, separateTimeOfArrival, -} from './train-driver'; +} from './train-driver.js'; const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom'); const customLogSymbol = Symbol.for('exercism.javascript.util.log'); diff --git a/exercises/concept/translation-service/api.js b/exercises/concept/translation-service/api.js index a4023a23bc..e6b02d207e 100644 --- a/exercises/concept/translation-service/api.js +++ b/exercises/concept/translation-service/api.js @@ -3,7 +3,7 @@ import { NotAvailable, Untranslatable, ConnectionError, -} from './errors'; +} from './errors.js'; const mutex = { current: false }; diff --git a/exercises/concept/translation-service/service.spec.js b/exercises/concept/translation-service/service.spec.js index 0514cb2b75..237b58a568 100644 --- a/exercises/concept/translation-service/service.spec.js +++ b/exercises/concept/translation-service/service.spec.js @@ -3,10 +3,10 @@ import { BatchIsEmpty, QualityThresholdNotMet, TranslationService, -} from './service'; +} from './service.js'; -import { ExternalApi } from './api'; -import { ConnectionError, NotAvailable, Untranslatable } from './errors'; +import { ExternalApi } from './api.js'; +import { ConnectionError, NotAvailable, Untranslatable } from './errors.js'; describe('Free service', () => { /** @type {TranslationService} */ diff --git a/exercises/concept/vehicle-purchase/vehicle-purchase.spec.js b/exercises/concept/vehicle-purchase/vehicle-purchase.spec.js index e38b916e6c..10490691b1 100644 --- a/exercises/concept/vehicle-purchase/vehicle-purchase.spec.js +++ b/exercises/concept/vehicle-purchase/vehicle-purchase.spec.js @@ -3,7 +3,7 @@ import { calculateResellPrice, chooseVehicle, needsLicense, -} from './vehicle-purchase'; +} from './vehicle-purchase.js'; describe('needsLicense', () => { test('requires a license for a car', () => { diff --git a/exercises/concept/windowing-system/windowing-system.spec.js b/exercises/concept/windowing-system/windowing-system.spec.js index 1798a924b3..e298093d34 100644 --- a/exercises/concept/windowing-system/windowing-system.spec.js +++ b/exercises/concept/windowing-system/windowing-system.spec.js @@ -4,7 +4,7 @@ import { ProgramWindow, Size, changeWindow, -} from './windowing-system'; +} from './windowing-system.js'; describe('Size class', () => { test('allows to create a new instance', () => { diff --git a/exercises/practice/accumulate/accumulate.spec.js b/exercises/practice/accumulate/accumulate.spec.js index 8db9a8fc3f..207d769556 100644 --- a/exercises/practice/accumulate/accumulate.spec.js +++ b/exercises/practice/accumulate/accumulate.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { accumulate } from './accumulate'; +import { accumulate } from './accumulate.js'; describe('accumulate()', () => { test('accumulation empty', () => { diff --git a/exercises/practice/acronym/acronym.spec.js b/exercises/practice/acronym/acronym.spec.js index 59a0eb7fe6..6cf6e5376f 100644 --- a/exercises/practice/acronym/acronym.spec.js +++ b/exercises/practice/acronym/acronym.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { parse } from './acronym'; +import { parse } from './acronym.js'; describe('Acronyms are produced from', () => { // basic diff --git a/exercises/practice/affine-cipher/affine-cipher.spec.js b/exercises/practice/affine-cipher/affine-cipher.spec.js index 507aad8de3..7e734df173 100644 --- a/exercises/practice/affine-cipher/affine-cipher.spec.js +++ b/exercises/practice/affine-cipher/affine-cipher.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { decode, encode } from './affine-cipher'; +import { decode, encode } from './affine-cipher.js'; describe('Affine cipher', () => { describe('encode', () => { diff --git a/exercises/practice/all-your-base/all-your-base.spec.js b/exercises/practice/all-your-base/all-your-base.spec.js index 5c84bc8114..55c3e42141 100644 --- a/exercises/practice/all-your-base/all-your-base.spec.js +++ b/exercises/practice/all-your-base/all-your-base.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { convert } from './all-your-base'; +import { convert } from './all-your-base.js'; describe('Converter', () => { test('single bit one to decimal', () => { diff --git a/exercises/practice/allergies/allergies.spec.js b/exercises/practice/allergies/allergies.spec.js index bc11b58911..763030a864 100644 --- a/exercises/practice/allergies/allergies.spec.js +++ b/exercises/practice/allergies/allergies.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Allergies } from './allergies'; +import { Allergies } from './allergies.js'; describe('Allergies', () => { describe('testing for eggs allergy', () => { diff --git a/exercises/practice/alphametics/alphametics.spec.js b/exercises/practice/alphametics/alphametics.spec.js index 07f990e446..d457096095 100644 --- a/exercises/practice/alphametics/alphametics.spec.js +++ b/exercises/practice/alphametics/alphametics.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { solve } from './alphametics'; +import { solve } from './alphametics.js'; describe('Solve the alphametics puzzle', () => { test('puzzle with three letters', () => { diff --git a/exercises/practice/anagram/.meta/config.json b/exercises/practice/anagram/.meta/config.json index 42cb3ee2a3..132d0a755a 100644 --- a/exercises/practice/anagram/.meta/config.json +++ b/exercises/practice/anagram/.meta/config.json @@ -27,7 +27,7 @@ ".meta/proof.ci.js" ] }, - "blurb": "Given a word and a list of possible anagrams, select the correct sublist.", + "blurb": "Find the words that use the same letters as another word.", "source": "Inspired by the Extreme Startup game", "source_url": "https://github.com/rchatley/extreme_startup", "custom": { diff --git a/exercises/practice/anagram/anagram.spec.js b/exercises/practice/anagram/anagram.spec.js index dc011aea9e..10eca7765e 100644 --- a/exercises/practice/anagram/anagram.spec.js +++ b/exercises/practice/anagram/anagram.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { findAnagrams } from './anagram'; +import { findAnagrams } from './anagram.js'; const areSetsEqual = (setA, setB) => setA.size === setB.size && [...setA].every((val) => setB.has(val)); diff --git a/exercises/practice/armstrong-numbers/armstrong-numbers.spec.js b/exercises/practice/armstrong-numbers/armstrong-numbers.spec.js index 4d380e8b7d..df84013a7b 100644 --- a/exercises/practice/armstrong-numbers/armstrong-numbers.spec.js +++ b/exercises/practice/armstrong-numbers/armstrong-numbers.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { isArmstrongNumber } from './armstrong-numbers'; +import { isArmstrongNumber } from './armstrong-numbers.js'; describe('Armstrong Numbers', () => { test('Zero is an Armstrong number', () => { diff --git a/exercises/practice/atbash-cipher/atbash-cipher.spec.js b/exercises/practice/atbash-cipher/atbash-cipher.spec.js index fd68ae2ad2..b99e75cd17 100644 --- a/exercises/practice/atbash-cipher/atbash-cipher.spec.js +++ b/exercises/practice/atbash-cipher/atbash-cipher.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { decode, encode } from './atbash-cipher'; +import { decode, encode } from './atbash-cipher.js'; describe('Atbash Cipher', () => { describe('encode', () => { diff --git a/exercises/practice/bank-account/bank-account.spec.js b/exercises/practice/bank-account/bank-account.spec.js index 406027a249..250e4ec4eb 100644 --- a/exercises/practice/bank-account/bank-account.spec.js +++ b/exercises/practice/bank-account/bank-account.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { BankAccount, ValueError } from './bank-account'; +import { BankAccount, ValueError } from './bank-account.js'; describe('Bank Account', () => { test('newly opened account has zero balance', () => { diff --git a/exercises/practice/beer-song/beer-song.spec.js b/exercises/practice/beer-song/beer-song.spec.js index 9738c5fe25..c61963f9c3 100644 --- a/exercises/practice/beer-song/beer-song.spec.js +++ b/exercises/practice/beer-song/beer-song.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { recite } from './beer-song'; +import { recite } from './beer-song.js'; describe('Beer Song', () => { describe('verse', () => { diff --git a/exercises/practice/binary-search-tree/binary-search-tree.spec.js b/exercises/practice/binary-search-tree/binary-search-tree.spec.js index 1f207a0a1b..ffda5f1440 100644 --- a/exercises/practice/binary-search-tree/binary-search-tree.spec.js +++ b/exercises/practice/binary-search-tree/binary-search-tree.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { BinarySearchTree } from './binary-search-tree'; +import { BinarySearchTree } from './binary-search-tree.js'; function recordAllData(bst) { const out = []; diff --git a/exercises/practice/binary-search/binary-search.spec.js b/exercises/practice/binary-search/binary-search.spec.js index a216ba93a2..2f0b1e4886 100644 --- a/exercises/practice/binary-search/binary-search.spec.js +++ b/exercises/practice/binary-search/binary-search.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { find } from './binary-search'; +import { find } from './binary-search.js'; describe('Binary Search', () => { test('finds a value in an array with one element', () => { diff --git a/exercises/practice/binary/binary.spec.js b/exercises/practice/binary/binary.spec.js index 415daed688..1d4785e39d 100644 --- a/exercises/practice/binary/binary.spec.js +++ b/exercises/practice/binary/binary.spec.js @@ -1,5 +1,5 @@ import { describe, test, expect, xtest } from '@jest/globals'; -import { Binary } from './binary'; +import { Binary } from './binary.js'; describe('binary', () => { test('0 is decimal 0', () => expect(new Binary('0').toDecimal()).toEqual(0)); diff --git a/exercises/practice/bob/.meta/tests.toml b/exercises/practice/bob/.meta/tests.toml index 5299e2895f..c6a4649601 100644 --- a/exercises/practice/bob/.meta/tests.toml +++ b/exercises/practice/bob/.meta/tests.toml @@ -9,17 +9,20 @@ # As user-added comments (using the # character) will be removed when this file # is regenerated, comments can be added via a `comment` key. -[e162fead-606f-437a-a166-d051915cea8e] -description = "stating something" +[8a2e771d-d6f1-4e3f-b6c6-b41495556e37] +description = "asking a question" [73a966dc-8017-47d6-bb32-cf07d1a5fcd9] description = "shouting" -[d6c98afd-df35-4806-b55e-2c457c3ab748] -description = "shouting gibberish" +[a5193c61-4a92-4f68-93e2-f554eb385ec6] +description = "forceful question" -[8a2e771d-d6f1-4e3f-b6c6-b41495556e37] -description = "asking a question" +[bc39f7c6-f543-41be-9a43-fd1c2f753fc0] +description = "silence" + +[e162fead-606f-437a-a166-d051915cea8e] +description = "stating something" [81080c62-4e4d-4066-b30a-48d8d76920d9] description = "asking a numeric question" @@ -27,23 +30,34 @@ description = "asking a numeric question" [2a02716d-685b-4e2e-a804-2adaf281c01e] description = "asking gibberish" -[c02f9179-ab16-4aa7-a8dc-940145c385f7] -description = "talking forcefully" +[bb0011c5-cd52-4a5b-8bfb-a87b6283b0e2] +description = "question with no letters" -[153c0e25-9bb5-4ec5-966e-598463658bcd] -description = "using acronyms in regular speech" +[9bfc677d-ea3a-45f2-be44-35bc8fa3753e] +description = "non-letters with question" -[a5193c61-4a92-4f68-93e2-f554eb385ec6] -description = "forceful question" +[8608c508-f7de-4b17-985b-811878b3cf45] +description = "prattling on" -[a20e0c54-2224-4dde-8b10-bd2cdd4f61bc] -description = "shouting numbers" +[05b304d6-f83b-46e7-81e0-4cd3ca647900] +description = "ending with whitespace" -[f7bc4b92-bdff-421e-a238-ae97f230ccac] -description = "no letters" +[66953780-165b-4e7e-8ce3-4bcb80b6385a] +description = "multiple line question" +include = false -[bb0011c5-cd52-4a5b-8bfb-a87b6283b0e2] -description = "question with no letters" +[2c7278ac-f955-4eb4-bf8f-e33eb4116a15] +description = "multiple line question" +reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a" + +[d6c98afd-df35-4806-b55e-2c457c3ab748] +description = "shouting gibberish" + +[3c954328-86fb-4c71-8961-e18d6a5e2517] +description = "shouting a statement containing a question mark" + +[a20e0c54-2224-4dde-8b10-bd2cdd4f61bc] +description = "shouting numbers" [496143c8-1c31-4c01-8a08-88427af85c66] description = "shouting with special characters" @@ -51,40 +65,29 @@ description = "shouting with special characters" [e6793c1c-43bd-4b8d-bc11-499aea73925f] description = "shouting with no exclamation mark" -[aa8097cc-c548-4951-8856-14a404dd236a] -description = "statement containing question mark" - -[9bfc677d-ea3a-45f2-be44-35bc8fa3753e] -description = "non-letters with question" - -[8608c508-f7de-4b17-985b-811878b3cf45] -description = "prattling on" - -[bc39f7c6-f543-41be-9a43-fd1c2f753fc0] -description = "silence" - [d6c47565-372b-4b09-b1dd-c40552b8378b] description = "prolonged silence" [4428f28d-4100-4d85-a902-e5a78cb0ecd3] description = "alternate silence" -[66953780-165b-4e7e-8ce3-4bcb80b6385a] -description = "multiple line question" -include = false +[72bd5ad3-9b2f-4931-a988-dce1f5771de2] +description = "other whitespace" -[5371ef75-d9ea-4103-bcfa-2da973ddec1b] -description = "starting with whitespace" +[c02f9179-ab16-4aa7-a8dc-940145c385f7] +description = "talking forcefully" -[05b304d6-f83b-46e7-81e0-4cd3ca647900] -description = "ending with whitespace" +[153c0e25-9bb5-4ec5-966e-598463658bcd] +description = "using acronyms in regular speech" -[72bd5ad3-9b2f-4931-a988-dce1f5771de2] -description = "other whitespace" +[f7bc4b92-bdff-421e-a238-ae97f230ccac] +description = "no letters" + +[aa8097cc-c548-4951-8856-14a404dd236a] +description = "statement containing question mark" + +[5371ef75-d9ea-4103-bcfa-2da973ddec1b] +description = "starting with whitespace" [12983553-8601-46a8-92fa-fcaa3bc4a2a0] description = "non-question ending with whitespace" - -[2c7278ac-f955-4eb4-bf8f-e33eb4116a15] -description = "multiple line question" -reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a" diff --git a/exercises/practice/bob/bob.spec.js b/exercises/practice/bob/bob.spec.js index f423c26044..129c38b4ad 100644 --- a/exercises/practice/bob/bob.spec.js +++ b/exercises/practice/bob/bob.spec.js @@ -1,10 +1,10 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { hey } from './bob'; +import { hey } from './bob.js'; describe('Bob', () => { - test('stating something', () => { - const result = hey('Tom-ay-to, tom-aaaah-to.'); - expect(result).toEqual('Whatever.'); + test('asking a question', () => { + const result = hey('Does this cryogenic chamber make me look fat?'); + expect(result).toEqual('Sure.'); }); xtest('shouting', () => { @@ -12,14 +12,19 @@ describe('Bob', () => { expect(result).toEqual('Whoa, chill out!'); }); - xtest('shouting gibberish', () => { - const result = hey('FCECDFCAAB'); - expect(result).toEqual('Whoa, chill out!'); + xtest('forceful question', () => { + const result = hey('WHAT THE HELL WERE YOU THINKING?'); + expect(result).toEqual("Calm down, I know what I'm doing!"); }); - xtest('asking a question', () => { - const result = hey('Does this cryogenic chamber make me look fat?'); - expect(result).toEqual('Sure.'); + xtest('silence', () => { + const result = hey(''); + expect(result).toEqual('Fine. Be that way!'); + }); + + xtest('stating something', () => { + const result = hey('Tom-ay-to, tom-aaaah-to.'); + expect(result).toEqual('Whatever.'); }); xtest('asking a numeric question', () => { @@ -32,64 +37,54 @@ describe('Bob', () => { expect(result).toEqual('Sure.'); }); - xtest('talking forcefully', () => { - const result = hey("Let's go make out behind the gym!"); - expect(result).toEqual('Whatever.'); - }); - - xtest('using acronyms in regular speech', () => { - const result = hey("It's OK if you don't want to go to the DMV."); - expect(result).toEqual('Whatever.'); + xtest('question with no letters', () => { + const result = hey('4?'); + expect(result).toEqual('Sure.'); }); - xtest('forceful question', () => { - const result = hey('WHAT THE HELL WERE YOU THINKING?'); - expect(result).toEqual("Calm down, I know what I'm doing!"); + xtest('non-letters with question', () => { + const result = hey(':) ?'); + expect(result).toEqual('Sure.'); }); - xtest('shouting numbers', () => { - const result = hey('1, 2, 3 GO!'); - expect(result).toEqual('Whoa, chill out!'); + xtest('prattling on', () => { + const result = hey('Wait! Hang on. Are you going to be OK?'); + expect(result).toEqual('Sure.'); }); - xtest('no letters', () => { - const result = hey('1, 2, 3'); - expect(result).toEqual('Whatever.'); + xtest('ending with whitespace', () => { + const result = hey('Okay if like my spacebar quite a bit? '); + expect(result).toEqual('Sure.'); }); - xtest('question with no letters', () => { - const result = hey('4?'); + xtest('multiple line question', () => { + const result = hey('\nDoes this cryogenic chamber make\n me look fat?'); expect(result).toEqual('Sure.'); }); - xtest('shouting with special characters', () => { - const result = hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!'); + xtest('shouting gibberish', () => { + const result = hey('FCECDFCAAB'); expect(result).toEqual('Whoa, chill out!'); }); - xtest('shouting with no exclamation mark', () => { - const result = hey('I HATE YOU'); + xtest('shouting a statement containing a question mark', () => { + const result = hey('DO LIONS EAT PEOPLE? AHHHHH.'); expect(result).toEqual('Whoa, chill out!'); }); - xtest('statement containing question mark', () => { - const result = hey('Ending with a ? means a question.'); - expect(result).toEqual('Whatever.'); - }); - - xtest('non-letters with question', () => { - const result = hey(':) ?'); - expect(result).toEqual('Sure.'); + xtest('shouting numbers', () => { + const result = hey('1, 2, 3 GO!'); + expect(result).toEqual('Whoa, chill out!'); }); - xtest('prattling on', () => { - const result = hey('Wait! Hang on. Are you going to be OK?'); - expect(result).toEqual('Sure.'); + xtest('shouting with special characters', () => { + const result = hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!'); + expect(result).toEqual('Whoa, chill out!'); }); - xtest('silence', () => { - const result = hey(''); - expect(result).toEqual('Fine. Be that way!'); + xtest('shouting with no exclamation mark', () => { + const result = hey('I HATE YOU'); + expect(result).toEqual('Whoa, chill out!'); }); xtest('prolonged silence', () => { @@ -102,24 +97,34 @@ describe('Bob', () => { expect(result).toEqual('Fine. Be that way!'); }); - xtest('multiple line question', () => { - const result = hey('\nDoes this cryogenic chamber make\n me look fat?'); - expect(result).toEqual('Sure.'); + xtest('other whitespace', () => { + const result = hey('\n\r \t'); + expect(result).toEqual('Fine. Be that way!'); }); - xtest('starting with whitespace', () => { - const result = hey(' hmmmmmmm...'); + xtest('talking forcefully', () => { + const result = hey("Let's go make out behind the gym!"); expect(result).toEqual('Whatever.'); }); - xtest('ending with whitespace', () => { - const result = hey('Okay if like my spacebar quite a bit? '); - expect(result).toEqual('Sure.'); + xtest('using acronyms in regular speech', () => { + const result = hey("It's OK if you don't want to go to the DMV."); + expect(result).toEqual('Whatever.'); }); - xtest('other whitespace', () => { - const result = hey('\n\r \t'); - expect(result).toEqual('Fine. Be that way!'); + xtest('no letters', () => { + const result = hey('1, 2, 3'); + expect(result).toEqual('Whatever.'); + }); + + xtest('statement containing question mark', () => { + const result = hey('Ending with a ? means a question.'); + expect(result).toEqual('Whatever.'); + }); + + xtest('starting with whitespace', () => { + const result = hey(' hmmmmmmm...'); + expect(result).toEqual('Whatever.'); }); xtest('non-question ending with whitespace', () => { diff --git a/exercises/practice/book-store/book-store.spec.js b/exercises/practice/book-store/book-store.spec.js index c0ae7bd61f..f0dfd78e4a 100644 --- a/exercises/practice/book-store/book-store.spec.js +++ b/exercises/practice/book-store/book-store.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { cost } from './book-store'; +import { cost } from './book-store.js'; describe('Book Store', () => { describe('Creating a basket', () => { diff --git a/exercises/practice/bottle-song/bottle-song.spec.js b/exercises/practice/bottle-song/bottle-song.spec.js index 75cde11eec..aacbf1b696 100644 --- a/exercises/practice/bottle-song/bottle-song.spec.js +++ b/exercises/practice/bottle-song/bottle-song.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { recite } from './bottle-song'; +import { recite } from './bottle-song.js'; describe('Bottle Song', () => { describe('verse', () => { diff --git a/exercises/practice/bowling/bowling.spec.js b/exercises/practice/bowling/bowling.spec.js index 6e95f7c5f6..a816edee37 100644 --- a/exercises/practice/bowling/bowling.spec.js +++ b/exercises/practice/bowling/bowling.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Bowling } from './bowling'; +import { Bowling } from './bowling.js'; describe('Bowling', () => { describe('Check game can be scored correctly.', () => { diff --git a/exercises/practice/camicia/camicia.spec.js b/exercises/practice/camicia/camicia.spec.js index 238db65cb2..f34b1e40d1 100644 --- a/exercises/practice/camicia/camicia.spec.js +++ b/exercises/practice/camicia/camicia.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { simulateGame } from './camicia'; +import { simulateGame } from './camicia.js'; describe('Camicia', () => { test('two cards, one trick', () => { diff --git a/exercises/practice/change/change.spec.js b/exercises/practice/change/change.spec.js index 8dbc425d12..6f5bb3843f 100644 --- a/exercises/practice/change/change.spec.js +++ b/exercises/practice/change/change.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Change } from './change'; +import { Change } from './change.js'; describe('Change', () => { test('change for 1 cent', () => { diff --git a/exercises/practice/circular-buffer/circular-buffer.spec.js b/exercises/practice/circular-buffer/circular-buffer.spec.js index 8d3d6d33c4..a7888ff770 100644 --- a/exercises/practice/circular-buffer/circular-buffer.spec.js +++ b/exercises/practice/circular-buffer/circular-buffer.spec.js @@ -2,7 +2,7 @@ import { describe, expect, test, xtest } from '@jest/globals'; import CircularBuffer, { BufferEmptyError, BufferFullError, -} from './circular-buffer'; +} from './circular-buffer.js'; describe('CircularBuffer', () => { test('reading empty buffer should fail', () => { diff --git a/exercises/practice/clock/clock.spec.js b/exercises/practice/clock/clock.spec.js index c480984839..864b791acd 100644 --- a/exercises/practice/clock/clock.spec.js +++ b/exercises/practice/clock/clock.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Clock } from './clock'; +import { Clock } from './clock.js'; describe('Clock', () => { describe('Creating a new clock with an initial time', () => { diff --git a/exercises/practice/collatz-conjecture/.docs/instructions.append.md b/exercises/practice/collatz-conjecture/.docs/instructions.append.md index 5ab8ae4861..df87531ce4 100644 --- a/exercises/practice/collatz-conjecture/.docs/instructions.append.md +++ b/exercises/practice/collatz-conjecture/.docs/instructions.append.md @@ -7,5 +7,5 @@ If `n` is not a positive integer, stop the program from being executed further a In JavaScript, this can be done using the `throw` statement. ```javascript -throw new Error('Only positive numbers are allowed'); +throw new Error('Only positive integers are allowed'); ``` diff --git a/exercises/practice/collatz-conjecture/collatz-conjecture.spec.js b/exercises/practice/collatz-conjecture/collatz-conjecture.spec.js index 87714b9b4e..0ab78b2950 100644 --- a/exercises/practice/collatz-conjecture/collatz-conjecture.spec.js +++ b/exercises/practice/collatz-conjecture/collatz-conjecture.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { steps } from './collatz-conjecture'; +import { steps } from './collatz-conjecture.js'; describe('steps()', () => { test('zero steps for one', () => { diff --git a/exercises/practice/complex-numbers/complex-numbers.spec.js b/exercises/practice/complex-numbers/complex-numbers.spec.js index 0275b31924..ba011c90eb 100644 --- a/exercises/practice/complex-numbers/complex-numbers.spec.js +++ b/exercises/practice/complex-numbers/complex-numbers.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { ComplexNumber } from './complex-numbers'; +import { ComplexNumber } from './complex-numbers.js'; describe('Complex numbers', () => { describe('Real part', () => { diff --git a/exercises/practice/connect/.meta/tests.toml b/exercises/practice/connect/.meta/tests.toml index 59ec615e39..951b87e5c4 100644 --- a/exercises/practice/connect/.meta/tests.toml +++ b/exercises/practice/connect/.meta/tests.toml @@ -1,6 +1,13 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. [6eff0df4-3e92-478d-9b54-d3e8b354db56] description = "an empty board has no winner" @@ -23,6 +30,12 @@ description = "nobody wins crossing adjacent angles" [cd61c143-92f6-4a8d-84d9-cb2b359e226b] description = "X wins crossing from left to right" +[495e33ed-30a9-4012-b46e-d7c4d5fe13c3] +description = "X wins with left-hand dead end fork" + +[ab167ab0-4a98-4d0f-a1c0-e1cddddc3d58] +description = "X wins with right-hand dead end fork" + [73d1eda6-16ab-4460-9904-b5f5dd401d0b] description = "O wins crossing from top to bottom" diff --git a/exercises/practice/connect/connect.spec.js b/exercises/practice/connect/connect.spec.js index a5fcca9ac7..71adb36ef0 100644 --- a/exercises/practice/connect/connect.spec.js +++ b/exercises/practice/connect/connect.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Board } from './connect'; +import { Board } from './connect.js'; describe('Judging a game of connect', () => { test('an empty board has no winner', () => { @@ -61,6 +61,16 @@ describe('Judging a game of connect', () => { expect(new Board(board).winner()).toEqual('X'); }); + xtest('X wins with left-hand dead end fork', () => { + const board = ['. . X .', ' X X . .', ' . X X X', ' O O O O']; + expect(new Board(board).winner()).toEqual('X'); + }); + + xtest('X wins with right-hand dead end fork', () => { + const board = ['. . X X', ' X X . .', ' . X X .', ' O O O O']; + expect(new Board(board).winner()).toEqual('X'); + }); + xtest('O wins crossing from top to bottom', () => { const board = [ '. O . .', diff --git a/exercises/practice/crypto-square/crypto-square.spec.js b/exercises/practice/crypto-square/crypto-square.spec.js index 2b45f1d56f..a98076d727 100644 --- a/exercises/practice/crypto-square/crypto-square.spec.js +++ b/exercises/practice/crypto-square/crypto-square.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Crypto } from './crypto-square'; +import { Crypto } from './crypto-square.js'; describe('Crypto', () => { test('empty plaintext results in an empty ciphertext', () => { diff --git a/exercises/practice/custom-set/custom-set.spec.js b/exercises/practice/custom-set/custom-set.spec.js index 08daf6367e..bbd8ef3ee8 100644 --- a/exercises/practice/custom-set/custom-set.spec.js +++ b/exercises/practice/custom-set/custom-set.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { CustomSet } from './custom-set'; +import { CustomSet } from './custom-set.js'; describe('CustomSet', () => { describe('empty: returns true if the set contains no elements', () => { diff --git a/exercises/practice/darts/darts.spec.js b/exercises/practice/darts/darts.spec.js index cbf63b5c71..7938f7c2aa 100644 --- a/exercises/practice/darts/darts.spec.js +++ b/exercises/practice/darts/darts.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { score } from './darts'; +import { score } from './darts.js'; describe('Darts', () => { test('Missed target', () => { diff --git a/exercises/practice/diamond/diamond.spec.js b/exercises/practice/diamond/diamond.spec.js index d92b9c9d4c..09f264f781 100644 --- a/exercises/practice/diamond/diamond.spec.js +++ b/exercises/practice/diamond/diamond.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { rows } from './diamond'; +import { rows } from './diamond.js'; describe('Diamond', () => { test("Degenerate case with a single 'A' row", () => { diff --git a/exercises/practice/difference-of-squares/difference-of-squares.spec.js b/exercises/practice/difference-of-squares/difference-of-squares.spec.js index 300c9e382c..3608c04722 100644 --- a/exercises/practice/difference-of-squares/difference-of-squares.spec.js +++ b/exercises/practice/difference-of-squares/difference-of-squares.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Squares } from './difference-of-squares'; +import { Squares } from './difference-of-squares.js'; describe('difference-of-squares', () => { const squares1 = new Squares(1); diff --git a/exercises/practice/diffie-hellman/diffie-hellman.spec.js b/exercises/practice/diffie-hellman/diffie-hellman.spec.js index 213a5df723..8fb45505cf 100644 --- a/exercises/practice/diffie-hellman/diffie-hellman.spec.js +++ b/exercises/practice/diffie-hellman/diffie-hellman.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { DiffieHellman } from './diffie-hellman'; +import { DiffieHellman } from './diffie-hellman.js'; describe('diffie-hellman', () => { test('throws an error if the constructor arguments are out of range', () => { diff --git a/exercises/practice/dnd-character/dnd-character.spec.js b/exercises/practice/dnd-character/dnd-character.spec.js index d930c140a1..e7f53550af 100644 --- a/exercises/practice/dnd-character/dnd-character.spec.js +++ b/exercises/practice/dnd-character/dnd-character.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Character, abilityModifier } from './dnd-character'; +import { Character, abilityModifier } from './dnd-character.js'; describe('D&D Character', () => { describe('Ability modifier', () => { diff --git a/exercises/practice/dominoes/dominoes.spec.js b/exercises/practice/dominoes/dominoes.spec.js index a99eb0663b..2d1906d825 100644 --- a/exercises/practice/dominoes/dominoes.spec.js +++ b/exercises/practice/dominoes/dominoes.spec.js @@ -1,5 +1,5 @@ import { describe, xdescribe, expect, test, xtest } from '@jest/globals'; -import { chain } from './dominoes'; +import { chain } from './dominoes.js'; function runTest(dominoes, expected) { if (expected) { diff --git a/exercises/practice/eliuds-eggs/eliuds-eggs.spec.js b/exercises/practice/eliuds-eggs/eliuds-eggs.spec.js index f27a0b29ee..250f217d5e 100644 --- a/exercises/practice/eliuds-eggs/eliuds-eggs.spec.js +++ b/exercises/practice/eliuds-eggs/eliuds-eggs.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { eggCount } from './eliuds-eggs'; +import { eggCount } from './eliuds-eggs.js'; describe('EliudsEggs', () => { test('0 eggs', () => { diff --git a/exercises/practice/error-handling/.docs/instructions.md b/exercises/practice/error-handling/.docs/instructions.md new file mode 100644 index 0000000000..25dd4d2928 --- /dev/null +++ b/exercises/practice/error-handling/.docs/instructions.md @@ -0,0 +1,8 @@ +# Instructions + +Implement various kinds of error handling and resource management. + +An important point of programming is how to handle errors and close resources even if errors occur. + +This exercise requires you to handle various errors. +Because error handling is rather programming language specific you'll have to refer to the tests for your track to see what's exactly required. diff --git a/exercises/practice/error-handling/.docs/introduction.md b/exercises/practice/error-handling/.docs/introduction.md new file mode 100644 index 0000000000..eb6b220e45 --- /dev/null +++ b/exercises/practice/error-handling/.docs/introduction.md @@ -0,0 +1,26 @@ +# Error Handling + +In this exercise, you will implement a function called `processString` that processes a given input string with proper error handling. + +You will learn how to: + +- Check input types and throw errors for invalid inputs. +- Throw errors for specific cases (e.g., empty strings). +- Return the uppercase version of the string if it is valid. +- Handle and catch errors using a try..catch block + + +Implement the processString function using a `tryâ€Ļcatch` block. + +Inside the `try` block: +- If the input is not a string, throw a `TypeError`. +- If the input is an empty string, return `null`. +- If input length is greater than 100, or less than 10, throw a `RangeError` +- If input contains a mix of letters and numbers, throw a `SyntaxError`. +- Otherwise, return the input in `uppercase`. + +*Don't forget to attach appropriate error messages then you throw! An informative and well structured error message can save you hours of debugging.* + +Inside the `catch` block: +- log the error's message using `console.log` +- `throw` the `error` so it can be tested for its type. diff --git a/exercises/practice/error-handling/.gitignore b/exercises/practice/error-handling/.gitignore new file mode 100644 index 0000000000..0c88ff6ec3 --- /dev/null +++ b/exercises/practice/error-handling/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/bin/configlet +/bin/configlet.exe +/package-lock.json +/yarn.lock diff --git a/exercises/practice/error-handling/.meta/config.json b/exercises/practice/error-handling/.meta/config.json new file mode 100644 index 0000000000..d657caee5e --- /dev/null +++ b/exercises/practice/error-handling/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": [ + "A-O-Emmanuel" + ], + "files": { + "solution": [ + "error-handling.js" + ], + "test": [ + "error-handling.spec.js" + ], + "example": [ + ".meta/proof.ci.js" + ] + }, + "blurb": "Implement various kinds of error handling and resource management." +} diff --git a/exercises/practice/error-handling/.meta/proof.ci.js b/exercises/practice/error-handling/.meta/proof.ci.js new file mode 100644 index 0000000000..f020a402af --- /dev/null +++ b/exercises/practice/error-handling/.meta/proof.ci.js @@ -0,0 +1,26 @@ +export const processString = (input) => { + try { + if (typeof input !== 'string') { + throw new TypeError('Input must be a string'); + } + if (input === '') { + return null; + } + if (input.length > 100) { + throw new RangeError('Input is too long'); + } + if (input.length < 10) { + throw new RangeError('Input is too short'); + } + if (/[a-zA-Z]/.test(input) && /\d/.test(input)) { + throw new SyntaxError( + 'Input cannot contain a mix of letters and numbers', + ); + } + + return input.toUpperCase(); + } catch (error) { + console.log(error.message); + throw error; + } +}; diff --git a/exercises/practice/error-handling/.npmrc b/exercises/practice/error-handling/.npmrc new file mode 100644 index 0000000000..d26df800bb --- /dev/null +++ b/exercises/practice/error-handling/.npmrc @@ -0,0 +1 @@ +audit=false diff --git a/exercises/practice/error-handling/LICENSE b/exercises/practice/error-handling/LICENSE new file mode 100644 index 0000000000..90e73be03b --- /dev/null +++ b/exercises/practice/error-handling/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Exercism + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/exercises/practice/error-handling/babel.config.js b/exercises/practice/error-handling/babel.config.js new file mode 100644 index 0000000000..a638497df1 --- /dev/null +++ b/exercises/practice/error-handling/babel.config.js @@ -0,0 +1,4 @@ +module.exports = { + presets: [['@exercism/babel-preset-javascript', { corejs: '3.40' }]], + plugins: [], +}; diff --git a/exercises/practice/error-handling/error-handling.js b/exercises/practice/error-handling/error-handling.js new file mode 100644 index 0000000000..42665c2b23 --- /dev/null +++ b/exercises/practice/error-handling/error-handling.js @@ -0,0 +1,8 @@ +// +// This is only a SKELETON file for the 'Error handling' exercise. It's been provided as a +// convenience to get you started writing code faster. +// + +export const processString = (input) => { + throw new Error('Remove this line and implement the function'); +}; diff --git a/exercises/practice/error-handling/error-handling.spec.js b/exercises/practice/error-handling/error-handling.spec.js new file mode 100644 index 0000000000..4e0137727b --- /dev/null +++ b/exercises/practice/error-handling/error-handling.spec.js @@ -0,0 +1,72 @@ +import { describe, expect, test, xtest } from '@jest/globals'; +import { processString } from './error-handling.js'; + +describe('Error Handling', () => { + test('never throws a generic Error for any invalid input', () => { + const invalidInputs = [ + 42, // TypeError + 'short', // RangeError (too short) + 'a'.repeat(101), // RangeError (too long) + '12345test6789text', // SyntaxError (mixed) + ]; + + for (const input of invalidInputs) { + let error; + + try { + processString(input); + } catch (err) { + error = err; + } + + expect(error).toBeInstanceOf(Error); + expect(error.constructor).not.toBe(Error); + expect(error.message).toEqual(expect.stringMatching(/.+/)); + } + }); + + xtest('throws TypeError if input is not a string', () => { + expect(() => processString(42)).toThrow( + expect.objectContaining({ + name: 'TypeError', + message: expect.stringMatching(/.+/), + }), + ); + }); + + xtest('throws error if input is too short', () => { + expect(() => processString('short')).toThrow( + expect.objectContaining({ + name: 'RangeError', + message: expect.stringMatching(/.+/), + }), + ); + }); + + xtest('throws error if input is too long', () => { + const longString = 'a'.repeat(101); + expect(() => processString(longString)).toThrow( + expect.objectContaining({ + name: 'RangeError', + message: expect.stringMatching(/.+/), + }), + ); + }); + + xtest('throws error if input contains a mix of letters and numbers', () => { + expect(() => processString('12345test6789text')).toThrow( + expect.objectContaining({ + name: 'SyntaxError', + message: expect.stringMatching(/.+/), + }), + ); + }); + + xtest('returns null if string is empty', () => { + expect(processString('')).toBeNull(); + }); + + xtest('returns uppercase string if input is valid', () => { + expect(processString('hellotherefriend')).toBe('HELLOTHEREFRIEND'); + }); +}); diff --git a/exercises/practice/error-handling/eslint.config.mjs b/exercises/practice/error-handling/eslint.config.mjs new file mode 100644 index 0000000000..ca517111ed --- /dev/null +++ b/exercises/practice/error-handling/eslint.config.mjs @@ -0,0 +1,45 @@ +// @ts-check + +import config from '@exercism/eslint-config-javascript'; +import maintainersConfig from '@exercism/eslint-config-javascript/maintainers.mjs'; + +import globals from 'globals'; + +export default [ + ...config, + ...maintainersConfig, + { + files: maintainersConfig[1].files, + rules: { + 'jest/expect-expect': ['warn', { assertFunctionNames: ['expect*'] }], + }, + }, + { + files: ['scripts/**/*.mjs'], + languageOptions: { + globals: { + ...globals.node, + }, + }, + }, + // <> + { + ignores: [ + // # Protected or generated + '/.appends/**/*', + '/.github/**/*', + '/.vscode/**/*', + + // # Binaries + '/bin/*', + + // # Configuration + '/config', + '/babel.config.js', + + // # Typings + '/exercises/**/global.d.ts', + '/exercises/**/env.d.ts', + ], + }, +]; diff --git a/exercises/practice/error-handling/jest.config.js b/exercises/practice/error-handling/jest.config.js new file mode 100644 index 0000000000..ec8e908127 --- /dev/null +++ b/exercises/practice/error-handling/jest.config.js @@ -0,0 +1,22 @@ +module.exports = { + verbose: true, + projects: [''], + testMatch: [ + '**/__tests__/**/*.[jt]s?(x)', + '**/test/**/*.[jt]s?(x)', + '**/?(*.)+(spec|test).[jt]s?(x)', + ], + testPathIgnorePatterns: [ + '/(?:production_)?node_modules/', + '.d.ts$', + '/test/fixtures', + '/test/helpers', + '__mocks__', + ], + transform: { + '^.+\\.[jt]sx?$': 'babel-jest', + }, + moduleNameMapper: { + '^(\\.\\/.+)\\.js$': '$1', + }, +}; diff --git a/exercises/practice/error-handling/package.json b/exercises/practice/error-handling/package.json new file mode 100644 index 0000000000..c2631ea755 --- /dev/null +++ b/exercises/practice/error-handling/package.json @@ -0,0 +1,38 @@ +{ + "name": "@exercism/javascript-practice-error-handling", + "description": "Exercism practice exercise on error-handling", + "author": "Katrina Owen", + "contributors": [ + "Derk-Jan Karrenbeld (https://derk-jan.com)", + "Tejas Bubane (https://tejasbubane.github.io/)" + ], + "private": true, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/exercism/javascript", + "directory": "exercises/practice/error-handling" + }, + "devDependencies": { + "@exercism/babel-preset-javascript": "^0.5.1", + "@exercism/eslint-config-javascript": "^0.8.1", + "@jest/globals": "^29.7.0", + "@types/node": "^24.3.0", + "@types/shelljs": "^0.8.17", + "babel-jest": "^29.7.0", + "core-js": "~3.42.0", + "diff": "^8.0.2", + "eslint": "^9.28.0", + "expect": "^29.7.0", + "globals": "^16.3.0", + "jest": "^29.7.0" + }, + "dependencies": {}, + "scripts": { + "lint": "corepack pnpm eslint .", + "test": "corepack pnpm jest", + "watch": "corepack pnpm jest --watch", + "format": "corepack pnpm prettier -w ." + }, + "packageManager": "pnpm@9.15.2" +} diff --git a/exercises/practice/etl/etl.spec.js b/exercises/practice/etl/etl.spec.js index 82a61e8eb4..815b1e3a89 100644 --- a/exercises/practice/etl/etl.spec.js +++ b/exercises/practice/etl/etl.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { transform } from './etl'; +import { transform } from './etl.js'; describe('Transform legacy to new', () => { test('single letter', () => { diff --git a/exercises/practice/flatten-array/flatten-array.spec.js b/exercises/practice/flatten-array/flatten-array.spec.js index c9a3c222cc..8268ad8803 100644 --- a/exercises/practice/flatten-array/flatten-array.spec.js +++ b/exercises/practice/flatten-array/flatten-array.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { flatten } from './flatten-array'; +import { flatten } from './flatten-array.js'; describe('FlattenArray', () => { test('empty', () => { diff --git a/exercises/practice/flower-field/flower-field.spec.js b/exercises/practice/flower-field/flower-field.spec.js index 5cd53b5f04..370c443862 100644 --- a/exercises/practice/flower-field/flower-field.spec.js +++ b/exercises/practice/flower-field/flower-field.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { annotate } from './flower-field'; +import { annotate } from './flower-field.js'; describe('Flower Field', () => { test('handles no rows', () => { diff --git a/exercises/practice/food-chain/food-chain.spec.js b/exercises/practice/food-chain/food-chain.spec.js index b7338e7651..971da9ec85 100644 --- a/exercises/practice/food-chain/food-chain.spec.js +++ b/exercises/practice/food-chain/food-chain.spec.js @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, test, xtest } from '@jest/globals'; -import { Song } from './food-chain'; +import { Song } from './food-chain.js'; describe('Food Chain', () => { let song; diff --git a/exercises/practice/forth/forth.spec.js b/exercises/practice/forth/forth.spec.js index df1e8765d7..db997f8e7b 100644 --- a/exercises/practice/forth/forth.spec.js +++ b/exercises/practice/forth/forth.spec.js @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, test, xtest } from '@jest/globals'; -import { Forth } from './forth'; +import { Forth } from './forth.js'; describe('Forth', () => { let forth; diff --git a/exercises/practice/game-of-life/game-of-life.spec.js b/exercises/practice/game-of-life/game-of-life.spec.js index 89d0ed1039..c71be99f82 100644 --- a/exercises/practice/game-of-life/game-of-life.spec.js +++ b/exercises/practice/game-of-life/game-of-life.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { GameOfLife } from './game-of-life'; +import { GameOfLife } from './game-of-life.js'; describe('Game of Life', () => { // Empty matrix diff --git a/exercises/practice/gigasecond/gigasecond.spec.js b/exercises/practice/gigasecond/gigasecond.spec.js index f107c3ec5e..1ad568cfac 100644 --- a/exercises/practice/gigasecond/gigasecond.spec.js +++ b/exercises/practice/gigasecond/gigasecond.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { gigasecond } from './gigasecond'; +import { gigasecond } from './gigasecond.js'; describe('Gigasecond', () => { // date only specification of time diff --git a/exercises/practice/go-counting/go-counting.spec.js b/exercises/practice/go-counting/go-counting.spec.js index 2338855894..470329707c 100644 --- a/exercises/practice/go-counting/go-counting.spec.js +++ b/exercises/practice/go-counting/go-counting.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { GoCounting } from './go-counting'; +import { GoCounting } from './go-counting.js'; describe('Go Counting', () => { describe('getTerritory', () => { diff --git a/exercises/practice/grade-school/grade-school.spec.js b/exercises/practice/grade-school/grade-school.spec.js index 7dca986a41..874d12471c 100644 --- a/exercises/practice/grade-school/grade-school.spec.js +++ b/exercises/practice/grade-school/grade-school.spec.js @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, test, xtest } from '@jest/globals'; -import { GradeSchool } from './grade-school'; +import { GradeSchool } from './grade-school.js'; describe('Grade School', () => { let school; diff --git a/exercises/practice/grains/grains.spec.js b/exercises/practice/grains/grains.spec.js index e36019cccb..d4e655f1a8 100644 --- a/exercises/practice/grains/grains.spec.js +++ b/exercises/practice/grains/grains.spec.js @@ -28,7 +28,7 @@ */ import { describe, expect, test, xtest } from '@jest/globals'; -import { square, total } from './grains'; +import { square, total } from './grains.js'; describe('Grains', () => { describe('returns the number of grains on the square', () => { diff --git a/exercises/practice/grep/.docs/introduction.md b/exercises/practice/grep/.docs/introduction.md new file mode 100644 index 0000000000..4041290465 --- /dev/null +++ b/exercises/practice/grep/.docs/introduction.md @@ -0,0 +1,5 @@ +# Introduction + +You have taken a job at a local library helping organize their collection of old books. +The student patrons are often hunting for half-remembered quotes to cite in their term papers. +Rather than manually read every book from cover to cover, you decide to build a small tool to scan them, looking for these partial quotes. diff --git a/exercises/practice/grep/.meta/config.json b/exercises/practice/grep/.meta/config.json index 4e6e96b3bf..01667c85ab 100644 --- a/exercises/practice/grep/.meta/config.json +++ b/exercises/practice/grep/.meta/config.json @@ -17,7 +17,7 @@ ".meta/proof.ci.js" ] }, - "blurb": "Search a file for lines matching a regular expression pattern. Return the line number and contents of each matching line.", + "blurb": "Search a file for lines matching a regular expression pattern.", "source": "Conversation with Nate Foster.", "source_url": "https://www.cs.cornell.edu/courses/cs3110/2014sp/hw/0/ps0.pdf", "custom": { diff --git a/exercises/practice/hamming/hamming.spec.js b/exercises/practice/hamming/hamming.spec.js index f8c083dca9..a77f4ba45c 100644 --- a/exercises/practice/hamming/hamming.spec.js +++ b/exercises/practice/hamming/hamming.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { compute } from './hamming'; +import { compute } from './hamming.js'; describe('Hamming', () => { test('empty strands', () => { diff --git a/exercises/practice/hello-world/hello-world.spec.js b/exercises/practice/hello-world/hello-world.spec.js index 1e8de8d78d..04c26ceb8b 100644 --- a/exercises/practice/hello-world/hello-world.spec.js +++ b/exercises/practice/hello-world/hello-world.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { hello } from './hello-world'; +import { hello } from './hello-world.js'; describe('Hello World', () => { test('Say Hi!', () => { diff --git a/exercises/practice/hexadecimal/hexadecimal.spec.js b/exercises/practice/hexadecimal/hexadecimal.spec.js index 80556433dd..1ecd1765e1 100644 --- a/exercises/practice/hexadecimal/hexadecimal.spec.js +++ b/exercises/practice/hexadecimal/hexadecimal.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { toDecimal } from './hexadecimal'; +import { toDecimal } from './hexadecimal.js'; describe('Hexadecimal', () => { test('hex 1 is decimal 1', () => { diff --git a/exercises/practice/high-scores/high-scores.spec.js b/exercises/practice/high-scores/high-scores.spec.js index 682a8e9778..ff54bb6b50 100644 --- a/exercises/practice/high-scores/high-scores.spec.js +++ b/exercises/practice/high-scores/high-scores.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { HighScores } from './high-scores'; +import { HighScores } from './high-scores.js'; describe('High Scores Test Suite', () => { test('List of scores', () => { diff --git a/exercises/practice/house/house.spec.js b/exercises/practice/house/house.spec.js index b720dc807b..a363f69f2e 100644 --- a/exercises/practice/house/house.spec.js +++ b/exercises/practice/house/house.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { House } from './house'; +import { House } from './house.js'; describe('House', () => { test('verse one - the house that jack built', () => { diff --git a/exercises/practice/isbn-verifier/isbn-verifier.spec.js b/exercises/practice/isbn-verifier/isbn-verifier.spec.js index 99d2cbf419..0261dd5ea3 100644 --- a/exercises/practice/isbn-verifier/isbn-verifier.spec.js +++ b/exercises/practice/isbn-verifier/isbn-verifier.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { isValid } from './isbn-verifier'; +import { isValid } from './isbn-verifier.js'; describe('ISBN Verifier', () => { test('valid isbn', () => { diff --git a/exercises/practice/isogram/.meta/config.json b/exercises/practice/isogram/.meta/config.json index 486f11ad0b..4294d83e25 100644 --- a/exercises/practice/isogram/.meta/config.json +++ b/exercises/practice/isogram/.meta/config.json @@ -22,7 +22,7 @@ ".meta/proof.ci.js" ] }, - "blurb": "Determine if a word or phrase is an isogram.", + "blurb": "Determine whether a phrase is an isogram, a word with no repeated letters.", "source": "Wikipedia", "source_url": "https://en.wikipedia.org/wiki/Isogram", "custom": { diff --git a/exercises/practice/isogram/isogram.spec.js b/exercises/practice/isogram/isogram.spec.js index 1b0162c717..2850316924 100644 --- a/exercises/practice/isogram/isogram.spec.js +++ b/exercises/practice/isogram/isogram.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { isIsogram } from './isogram'; +import { isIsogram } from './isogram.js'; describe('Isogram', () => { describe('Check if the given string is an isogram', () => { diff --git a/exercises/practice/killer-sudoku-helper/killer-sudoku-helper.spec.js b/exercises/practice/killer-sudoku-helper/killer-sudoku-helper.spec.js index 61167f7e6a..4802c305ed 100644 --- a/exercises/practice/killer-sudoku-helper/killer-sudoku-helper.spec.js +++ b/exercises/practice/killer-sudoku-helper/killer-sudoku-helper.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { combinations } from './killer-sudoku-helper'; +import { combinations } from './killer-sudoku-helper.js'; describe('Trivial 1-digit cages', () => { test('1', () => { diff --git a/exercises/practice/kindergarten-garden/kindergarten-garden.spec.js b/exercises/practice/kindergarten-garden/kindergarten-garden.spec.js index 3d980989e8..2cf7e521ed 100644 --- a/exercises/practice/kindergarten-garden/kindergarten-garden.spec.js +++ b/exercises/practice/kindergarten-garden/kindergarten-garden.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Garden } from './kindergarten-garden'; +import { Garden } from './kindergarten-garden.js'; describe('partial Garden', () => { test('garden with single student', () => { diff --git a/exercises/practice/knapsack/knapsack.spec.js b/exercises/practice/knapsack/knapsack.spec.js index cbf4b9c64d..3f47b26850 100644 --- a/exercises/practice/knapsack/knapsack.spec.js +++ b/exercises/practice/knapsack/knapsack.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test } from '@jest/globals'; -import { knapsack } from './knapsack'; +import { knapsack } from './knapsack.js'; describe('Knapsack', () => { test('no items', () => { diff --git a/exercises/practice/largest-series-product/largest-series-product.spec.js b/exercises/practice/largest-series-product/largest-series-product.spec.js index bfb6560b5c..803e14ec89 100644 --- a/exercises/practice/largest-series-product/largest-series-product.spec.js +++ b/exercises/practice/largest-series-product/largest-series-product.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { largestProduct } from './largest-series-product'; +import { largestProduct } from './largest-series-product.js'; describe('Largest Series Product', () => { test('finds the largest product if span equals length', () => { diff --git a/exercises/practice/leap/leap.spec.js b/exercises/practice/leap/leap.spec.js index 3aba100a2c..68ae2e845e 100644 --- a/exercises/practice/leap/leap.spec.js +++ b/exercises/practice/leap/leap.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { isLeap } from './leap'; +import { isLeap } from './leap.js'; describe('A leap year', () => { test('year not divisible by 4 in common year', () => { diff --git a/exercises/practice/ledger/ledger.spec.js b/exercises/practice/ledger/ledger.spec.js index 1d9fa4053f..0eed5465bc 100644 --- a/exercises/practice/ledger/ledger.spec.js +++ b/exercises/practice/ledger/ledger.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { createEntry, formatEntries } from './ledger'; +import { createEntry, formatEntries } from './ledger.js'; describe('Ledger', () => { test('empty ledger', () => { diff --git a/exercises/practice/lens-person/.meta/proof.ci.js b/exercises/practice/lens-person/.meta/proof.ci.js index 10e80198ca..a66d1458e0 100644 --- a/exercises/practice/lens-person/.meta/proof.ci.js +++ b/exercises/practice/lens-person/.meta/proof.ci.js @@ -1,9 +1,9 @@ /* eslint-disable no-unused-vars */ -import { Address } from '../address'; -import { Born } from '../born'; -import { Lens } from '../lens'; -import { Name } from '../name'; -import { Person } from '../person'; +import { Address } from '../address.js'; +import { Born } from '../born.js'; +import { Lens } from '../lens.js'; +import { Name } from '../name.js'; +import { Person } from '../person.js'; // Implement the nameLens with the getter and setter export const nameLens = new Lens( diff --git a/exercises/practice/lens-person/lens-person.js b/exercises/practice/lens-person/lens-person.js index e5fb820a18..1b94501b76 100644 --- a/exercises/practice/lens-person/lens-person.js +++ b/exercises/practice/lens-person/lens-person.js @@ -4,11 +4,11 @@ // /* eslint-disable no-unused-vars */ -import { Person } from './person'; -import { Name } from './name'; -import { Born } from './born'; -import { Address } from './address'; -import { Lens } from './lens'; +import { Person } from './person.js'; +import { Name } from './name.js'; +import { Born } from './born.js'; +import { Address } from './address.js'; +import { Lens } from './lens.js'; // Implement the nameLens with the getter and setter export const nameLens = new Lens( diff --git a/exercises/practice/lens-person/lens-person.spec.js b/exercises/practice/lens-person/lens-person.spec.js index 6788eb043e..8f50235eb4 100644 --- a/exercises/practice/lens-person/lens-person.spec.js +++ b/exercises/practice/lens-person/lens-person.spec.js @@ -1,10 +1,10 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Address } from './address'; -import { Born } from './born'; -import { Name } from './name'; -import { Person } from './person'; +import { Address } from './address.js'; +import { Born } from './born.js'; +import { Name } from './name.js'; +import { Person } from './person.js'; -import { bornAtLens, nameLens, streetLens } from './lens-person'; +import { bornAtLens, nameLens, streetLens } from './lens-person.js'; // test data const person = new Person( diff --git a/exercises/practice/line-up/.meta/tests.toml b/exercises/practice/line-up/.meta/tests.toml index 36fdf1d0cd..dd66fc1585 100644 --- a/exercises/practice/line-up/.meta/tests.toml +++ b/exercises/practice/line-up/.meta/tests.toml @@ -51,9 +51,24 @@ description = "format non-exceptional ordinal numeral 13" [2bdcebc5-c029-4874-b6cc-e9bec80d603a] description = "format exceptional ordinal numeral 21" +[a98e2e22-ab41-4557-a7c2-efedc19c16da] +description = "format exceptional ordinal numeral 22 ending in nd even though it is a multiple of 11" + +[ab45d2fb-e0ee-4016-b605-76917584db0a] +description = "format exceptional ordinal numeral 33 ending in rd even though it is a multiple of 11" + +[c9243603-9f17-45b3-9a41-db9ebdbf08e1] +description = "format exceptional ordinal numeral 52 ending in nd even though it is a multiple of 13" + [74ee2317-0295-49d2-baf0-d56bcefa14e3] description = "format exceptional ordinal numeral 62" +[3f6c408c-4331-42b6-bb6c-3ad0823e568a] +description = "format non-exceptional ordinal numeral 72 ending in nd even though it is a multiple of 12" + +[8db52cd9-9689-413f-a812-6c36fcfd0d07] +description = "format exceptional ordinal numeral 91 ending in st even though it is a multiple of 13" + [b37c332d-7f68-40e3-8503-e43cbd67a0c4] description = "format exceptional ordinal numeral 100" @@ -65,3 +80,6 @@ description = "format non-exceptional ordinal numeral 112" [06b62efe-199e-4ce7-970d-4bf73945713f] description = "format exceptional ordinal numeral 123" + +[6792c54e-59a7-4faf-839a-c4bb61014229] +description = "format large number 972 ending in nd even though it is a multiple of 12" diff --git a/exercises/practice/line-up/line-up.spec.js b/exercises/practice/line-up/line-up.spec.js index 62877284de..7719965e6a 100644 --- a/exercises/practice/line-up/line-up.spec.js +++ b/exercises/practice/line-up/line-up.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { format } from './line-up'; +import { format } from './line-up.js'; describe('Line Up', () => { test('format smallest non-exceptional ordinal numeral 4', () => { @@ -86,12 +86,42 @@ describe('Line Up', () => { ); }); + xtest('format exceptional ordinal numeral 22 ending in nd even though it is a multiple of 11', () => { + expect(format('Ingrid', 22)).toBe( + 'Ingrid, you are the 22nd customer we serve today. Thank you!', + ); + }); + + xtest('format exceptional ordinal numeral 33 ending in rd even though it is a multiple of 11', () => { + expect(format('Mario', 33)).toBe( + 'Mario, you are the 33rd customer we serve today. Thank you!', + ); + }); + + xtest('format exceptional ordinal numeral 52 ending in nd even though it is a multiple of 13', () => { + expect(format('Quentin', 52)).toBe( + 'Quentin, you are the 52nd customer we serve today. Thank you!', + ); + }); + xtest('format exceptional ordinal numeral 62', () => { expect(format('Nayra', 62)).toBe( 'Nayra, you are the 62nd customer we serve today. Thank you!', ); }); + xtest('format non-exceptional ordinal numeral 72 ending in nd even though it is a multiple of 12', () => { + expect(format('Ugo', 72)).toBe( + 'Ugo, you are the 72nd customer we serve today. Thank you!', + ); + }); + + xtest('format exceptional ordinal numeral 91 ending in st even though it is a multiple of 13', () => { + expect(format('Boris', 91)).toBe( + 'Boris, you are the 91st customer we serve today. Thank you!', + ); + }); + xtest('format exceptional ordinal numeral 100', () => { expect(format('John', 100)).toBe( 'John, you are the 100th customer we serve today. Thank you!', @@ -115,4 +145,10 @@ describe('Line Up', () => { 'Yma, you are the 123rd customer we serve today. Thank you!', ); }); + + xtest('format large number 972 ending in nd even though it is a multiple of 12', () => { + expect(format('Elias', 972)).toBe( + 'Elias, you are the 972nd customer we serve today. Thank you!', + ); + }); }); diff --git a/exercises/practice/linked-list/linked-list.spec.js b/exercises/practice/linked-list/linked-list.spec.js index feb682d58b..548eea99c4 100644 --- a/exercises/practice/linked-list/linked-list.spec.js +++ b/exercises/practice/linked-list/linked-list.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { LinkedList } from './linked-list'; +import { LinkedList } from './linked-list.js'; describe('LinkedList', () => { test('pop gets last element from the list', () => { diff --git a/exercises/practice/list-ops/list-ops.spec.js b/exercises/practice/list-ops/list-ops.spec.js index 7ba71ef2bb..244136da28 100644 --- a/exercises/practice/list-ops/list-ops.spec.js +++ b/exercises/practice/list-ops/list-ops.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { List } from './list-ops'; +import { List } from './list-ops.js'; describe('append entries to a list and return the new list', () => { test('empty lists', () => { diff --git a/exercises/practice/luhn/luhn.spec.js b/exercises/practice/luhn/luhn.spec.js index 6cd37fe16f..02bc80d79b 100644 --- a/exercises/practice/luhn/luhn.spec.js +++ b/exercises/practice/luhn/luhn.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { valid } from './luhn'; +import { valid } from './luhn.js'; describe('Luhn', () => { test('single digit strings can not be valid', () => { diff --git a/exercises/practice/markdown/markdown.spec.js b/exercises/practice/markdown/markdown.spec.js index ee7417c100..1c285216e3 100644 --- a/exercises/practice/markdown/markdown.spec.js +++ b/exercises/practice/markdown/markdown.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { parse } from './markdown'; +import { parse } from './markdown.js'; describe('Markdown', () => { test('parses normal text as a paragraph', () => { diff --git a/exercises/practice/matching-brackets/matching-brackets.spec.js b/exercises/practice/matching-brackets/matching-brackets.spec.js index 2f08561b28..83c416516a 100644 --- a/exercises/practice/matching-brackets/matching-brackets.spec.js +++ b/exercises/practice/matching-brackets/matching-brackets.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { isPaired } from './matching-brackets'; +import { isPaired } from './matching-brackets.js'; describe('Matching Brackets', () => { test('paired square brackets', () => { diff --git a/exercises/practice/matrix/matrix.spec.js b/exercises/practice/matrix/matrix.spec.js index 594c376a34..e1d786ac66 100644 --- a/exercises/practice/matrix/matrix.spec.js +++ b/exercises/practice/matrix/matrix.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Matrix } from './matrix'; +import { Matrix } from './matrix.js'; describe('Matrix', () => { test('extract row from one number matrix', () => { diff --git a/exercises/practice/meetup/meetup.spec.js b/exercises/practice/meetup/meetup.spec.js index 540da01264..b0c9dc922c 100644 --- a/exercises/practice/meetup/meetup.spec.js +++ b/exercises/practice/meetup/meetup.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { meetup } from './meetup'; +import { meetup } from './meetup.js'; describe('Meetup', () => { test('monteenth of May 2013', () => { diff --git a/exercises/practice/micro-blog/micro-blog.spec.js b/exercises/practice/micro-blog/micro-blog.spec.js index 692b283b0b..ca966a9a8b 100644 --- a/exercises/practice/micro-blog/micro-blog.spec.js +++ b/exercises/practice/micro-blog/micro-blog.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { truncate } from './micro-blog'; +import { truncate } from './micro-blog.js'; describe('Micro-blog', () => { test('English language short', () => { diff --git a/exercises/practice/minesweeper/minesweeper.spec.js b/exercises/practice/minesweeper/minesweeper.spec.js index ff2250ade2..7932efc21c 100644 --- a/exercises/practice/minesweeper/minesweeper.spec.js +++ b/exercises/practice/minesweeper/minesweeper.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { annotate } from './minesweeper'; +import { annotate } from './minesweeper.js'; describe(')', () => { test('handles no rows', () => { diff --git a/exercises/practice/nth-prime/nth-prime.spec.js b/exercises/practice/nth-prime/nth-prime.spec.js index 59613d9f12..1543473750 100644 --- a/exercises/practice/nth-prime/nth-prime.spec.js +++ b/exercises/practice/nth-prime/nth-prime.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { prime } from './nth-prime'; +import { prime } from './nth-prime.js'; describe('nth-prime', () => { test('first prime', () => { diff --git a/exercises/practice/nucleotide-count/.meta/config.json b/exercises/practice/nucleotide-count/.meta/config.json index d2f001af9d..35f321a378 100644 --- a/exercises/practice/nucleotide-count/.meta/config.json +++ b/exercises/practice/nucleotide-count/.meta/config.json @@ -20,7 +20,7 @@ ] }, "blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", - "source": "The Calculating DNA Nucleotides_problem at Rosalind", + "source": "The Counting DNA Nucleotides problem at Rosalind", "source_url": "https://rosalind.info/problems/dna/", "custom": { "version.tests.compatibility": "jest-27", diff --git a/exercises/practice/nucleotide-count/nucleotide-count.spec.js b/exercises/practice/nucleotide-count/nucleotide-count.spec.js index d767e01040..cc5184755e 100644 --- a/exercises/practice/nucleotide-count/nucleotide-count.spec.js +++ b/exercises/practice/nucleotide-count/nucleotide-count.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { countNucleotides } from './nucleotide-count'; +import { countNucleotides } from './nucleotide-count.js'; describe('count all nucleotides in a strand', () => { test('empty strand', () => { diff --git a/exercises/practice/ocr-numbers/ocr-numbers.spec.js b/exercises/practice/ocr-numbers/ocr-numbers.spec.js index 890e7052b3..edc2d3009f 100644 --- a/exercises/practice/ocr-numbers/ocr-numbers.spec.js +++ b/exercises/practice/ocr-numbers/ocr-numbers.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { convert } from './ocr-numbers'; +import { convert } from './ocr-numbers.js'; describe('ocr', () => { test('recognizes zero', () => { diff --git a/exercises/practice/octal/octal.spec.js b/exercises/practice/octal/octal.spec.js index a6a9eae55e..eca9fe56fb 100644 --- a/exercises/practice/octal/octal.spec.js +++ b/exercises/practice/octal/octal.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Octal } from './octal'; +import { Octal } from './octal.js'; describe('octal', () => { test('1 is decimal 1', () => { diff --git a/exercises/practice/palindrome-products/palindrome-products.spec.js b/exercises/practice/palindrome-products/palindrome-products.spec.js index d3b60b9da0..be3d1f8fe6 100644 --- a/exercises/practice/palindrome-products/palindrome-products.spec.js +++ b/exercises/practice/palindrome-products/palindrome-products.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Palindromes } from './palindrome-products'; +import { Palindromes } from './palindrome-products.js'; describe('Palindromes', () => { test('smallest palindrome from single digit factors', () => { diff --git a/exercises/practice/pangram/.meta/config.json b/exercises/practice/pangram/.meta/config.json index 13c4d2e850..cd92723bb7 100644 --- a/exercises/practice/pangram/.meta/config.json +++ b/exercises/practice/pangram/.meta/config.json @@ -24,7 +24,7 @@ ".meta/proof.ci.js" ] }, - "blurb": "Determine if a sentence is a pangram.", + "blurb": "Determine whether a phrase uses every letter in the Latin alphabet.", "source": "Wikipedia", "source_url": "https://en.wikipedia.org/wiki/Pangram", "custom": { diff --git a/exercises/practice/pangram/pangram.spec.js b/exercises/practice/pangram/pangram.spec.js index 9f3b7c5c9f..b9ba2313c1 100644 --- a/exercises/practice/pangram/pangram.spec.js +++ b/exercises/practice/pangram/pangram.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { isPangram } from './pangram'; +import { isPangram } from './pangram.js'; describe('Pangram()', () => { test('empty sentence', () => { diff --git a/exercises/practice/parallel-letter-frequency/parallel-letter-frequency.spec.js b/exercises/practice/parallel-letter-frequency/parallel-letter-frequency.spec.js index c032236994..5856cebd2e 100644 --- a/exercises/practice/parallel-letter-frequency/parallel-letter-frequency.spec.js +++ b/exercises/practice/parallel-letter-frequency/parallel-letter-frequency.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { parallelLetterFrequency } from './parallel-letter-frequency'; +import { parallelLetterFrequency } from './parallel-letter-frequency.js'; describe('ParallelLetterFrequency', () => { test('no texts', async () => { diff --git a/exercises/practice/pascals-triangle/pascals-triangle.spec.js b/exercises/practice/pascals-triangle/pascals-triangle.spec.js index e910370fb3..bd52b1180e 100644 --- a/exercises/practice/pascals-triangle/pascals-triangle.spec.js +++ b/exercises/practice/pascals-triangle/pascals-triangle.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { rows } from './pascals-triangle'; +import { rows } from './pascals-triangle.js'; describe('Pascals Triangle', () => { describe("Given a count, return a collection of that many rows of pascal's triangle", () => { diff --git a/exercises/practice/perfect-numbers/.meta/config.json b/exercises/practice/perfect-numbers/.meta/config.json index 834b86858e..275e5ba8ae 100644 --- a/exercises/practice/perfect-numbers/.meta/config.json +++ b/exercises/practice/perfect-numbers/.meta/config.json @@ -23,7 +23,7 @@ }, "blurb": "Determine if a number is perfect, abundant, or deficient based on Nicomachus' (60 - 120 CE) classification scheme for positive integers.", "source": "Taken from Chapter 2 of Functional Thinking by Neal Ford.", - "source_url": "https://www.oreilly.com/library/view/functional-thinking/9781449365509/", + "source_url": "https://nealford.com/books/functionalthinking.html", "custom": { "version.tests.compatibility": "jest-27", "flag.tests.task-per-describe": false, diff --git a/exercises/practice/perfect-numbers/perfect-numbers.spec.js b/exercises/practice/perfect-numbers/perfect-numbers.spec.js index e89a142014..96d373a248 100644 --- a/exercises/practice/perfect-numbers/perfect-numbers.spec.js +++ b/exercises/practice/perfect-numbers/perfect-numbers.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { classify } from './perfect-numbers'; +import { classify } from './perfect-numbers.js'; describe('Exercise - Perfect Numbers', () => { describe('Invalid Inputs', () => { diff --git a/exercises/practice/phone-number/phone-number.spec.js b/exercises/practice/phone-number/phone-number.spec.js index e3ae5be50b..a928eb51ee 100644 --- a/exercises/practice/phone-number/phone-number.spec.js +++ b/exercises/practice/phone-number/phone-number.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { clean } from './phone-number'; +import { clean } from './phone-number.js'; describe('Phone Number', () => { describe('Cleanup user-entered phone numbers', () => { diff --git a/exercises/practice/pig-latin/pig-latin.spec.js b/exercises/practice/pig-latin/pig-latin.spec.js index 204b0344d6..951388ac13 100644 --- a/exercises/practice/pig-latin/pig-latin.spec.js +++ b/exercises/practice/pig-latin/pig-latin.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { translate } from './pig-latin'; +import { translate } from './pig-latin.js'; describe('Pig Latin', () => { describe('ay is added to words that start with vowels', () => { diff --git a/exercises/practice/point-mutations/point-mutations.spec.js b/exercises/practice/point-mutations/point-mutations.spec.js index b81c66f394..c754e7132e 100644 --- a/exercises/practice/point-mutations/point-mutations.spec.js +++ b/exercises/practice/point-mutations/point-mutations.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { DNA } from './point-mutations'; +import { DNA } from './point-mutations.js'; describe('DNA', () => { test('no difference between empty strands', () => { diff --git a/exercises/practice/poker/poker.spec.js b/exercises/practice/poker/poker.spec.js index 97d8dd4737..49dae64097 100644 --- a/exercises/practice/poker/poker.spec.js +++ b/exercises/practice/poker/poker.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { bestHands } from './poker'; +import { bestHands } from './poker.js'; describe('Poker', () => { test('single hand always wins', () => { diff --git a/exercises/practice/prime-factors/prime-factors.spec.js b/exercises/practice/prime-factors/prime-factors.spec.js index b1849a49b6..8a05ee8cbb 100644 --- a/exercises/practice/prime-factors/prime-factors.spec.js +++ b/exercises/practice/prime-factors/prime-factors.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { primeFactors } from './prime-factors'; +import { primeFactors } from './prime-factors.js'; describe('returns prime factors for the given input number', () => { test('no factors', () => expect(primeFactors(1)).toEqual([])); diff --git a/exercises/practice/prism/prism.spec.js b/exercises/practice/prism/prism.spec.js index 7b5c504f01..e1fc879cee 100644 --- a/exercises/practice/prism/prism.spec.js +++ b/exercises/practice/prism/prism.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { findSequence } from './prism'; +import { findSequence } from './prism.js'; describe('Prism', () => { test('zero prisms', () => { diff --git a/exercises/practice/promises/promises.spec.js b/exercises/practice/promises/promises.spec.js index 1b5c721bf3..f97a9fb313 100644 --- a/exercises/practice/promises/promises.spec.js +++ b/exercises/practice/promises/promises.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { all, allSettled, any, promisify, race } from './promises'; +import { all, allSettled, any, promisify, race } from './promises.js'; describe('promises', () => { const failedCallback = new Error('Failed callback'); diff --git a/exercises/practice/protein-translation/protein-translation.spec.js b/exercises/practice/protein-translation/protein-translation.spec.js index 63359ec9ca..9e7a5ed7b8 100644 --- a/exercises/practice/protein-translation/protein-translation.spec.js +++ b/exercises/practice/protein-translation/protein-translation.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { translate } from './protein-translation'; +import { translate } from './protein-translation.js'; describe('ProteinTranslation', () => { test('Empty RNA sequence results in no proteins', () => { diff --git a/exercises/practice/proverb/proverb.spec.js b/exercises/practice/proverb/proverb.spec.js index 2e33118231..fbbb5da965 100644 --- a/exercises/practice/proverb/proverb.spec.js +++ b/exercises/practice/proverb/proverb.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { proverb } from './proverb'; +import { proverb } from './proverb.js'; describe('Proverb', () => { test('zero pieces', () => { diff --git a/exercises/practice/pythagorean-triplet/pythagorean-triplet.spec.js b/exercises/practice/pythagorean-triplet/pythagorean-triplet.spec.js index 0db403e95b..b553791a88 100644 --- a/exercises/practice/pythagorean-triplet/pythagorean-triplet.spec.js +++ b/exercises/practice/pythagorean-triplet/pythagorean-triplet.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { triplets } from './pythagorean-triplet'; +import { triplets } from './pythagorean-triplet.js'; function tripletsWithSum(sum, options = {}) { return triplets({ ...options, sum }).map((triplet) => diff --git a/exercises/practice/queen-attack/queen-attack.spec.js b/exercises/practice/queen-attack/queen-attack.spec.js index 97794800b4..ddbd88a098 100644 --- a/exercises/practice/queen-attack/queen-attack.spec.js +++ b/exercises/practice/queen-attack/queen-attack.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { QueenAttack } from './queen-attack'; +import { QueenAttack } from './queen-attack.js'; describe('Queens', () => { describe('Test creation of Queens with valid and invalid positions', () => { diff --git a/exercises/practice/rail-fence-cipher/rail-fence-cipher.spec.js b/exercises/practice/rail-fence-cipher/rail-fence-cipher.spec.js index 00e9fb378b..9555eacba7 100644 --- a/exercises/practice/rail-fence-cipher/rail-fence-cipher.spec.js +++ b/exercises/practice/rail-fence-cipher/rail-fence-cipher.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { decode, encode } from './rail-fence-cipher'; +import { decode, encode } from './rail-fence-cipher.js'; describe('Rail Fence Cipher', () => { describe('encode', () => { diff --git a/exercises/practice/raindrops/raindrops.spec.js b/exercises/practice/raindrops/raindrops.spec.js index 946fb849d8..3570d813d8 100644 --- a/exercises/practice/raindrops/raindrops.spec.js +++ b/exercises/practice/raindrops/raindrops.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { convert } from './raindrops'; +import { convert } from './raindrops.js'; describe('Raindrops', () => { test('the sound for 1 is 1', () => expect(convert(1)).toEqual('1')); diff --git a/exercises/practice/rational-numbers/rational-numbers.spec.js b/exercises/practice/rational-numbers/rational-numbers.spec.js index 5118277a25..d0fdbfbd1e 100644 --- a/exercises/practice/rational-numbers/rational-numbers.spec.js +++ b/exercises/practice/rational-numbers/rational-numbers.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Rational } from './rational-numbers'; +import { Rational } from './rational-numbers.js'; describe('Addition', () => { test('Add two positive rational numbers', () => { diff --git a/exercises/practice/react/react.spec.js b/exercises/practice/react/react.spec.js index 2ad0a8e5f8..198b74d247 100644 --- a/exercises/practice/react/react.spec.js +++ b/exercises/practice/react/react.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { CallbackCell, ComputeCell, InputCell } from './react'; +import { CallbackCell, ComputeCell, InputCell } from './react.js'; describe('React module', () => { test('accepts input', () => { diff --git a/exercises/practice/rectangles/rectangles.spec.js b/exercises/practice/rectangles/rectangles.spec.js index 6e1ee3919c..12cc758c51 100644 --- a/exercises/practice/rectangles/rectangles.spec.js +++ b/exercises/practice/rectangles/rectangles.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { count } from './rectangles'; +import { count } from './rectangles.js'; describe('Rectangles', () => { test('no rows', () => { diff --git a/exercises/practice/relative-distance/relative-distance.spec.js b/exercises/practice/relative-distance/relative-distance.spec.js index 57d5b7187f..c859226ebb 100644 --- a/exercises/practice/relative-distance/relative-distance.spec.js +++ b/exercises/practice/relative-distance/relative-distance.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { degreesOfSeparation } from './relative-distance'; +import { degreesOfSeparation } from './relative-distance.js'; describe('RelativeDistance', () => { test('Direct parent-child relation', () => { diff --git a/exercises/practice/resistor-color-duo/resistor-color-duo.spec.js b/exercises/practice/resistor-color-duo/resistor-color-duo.spec.js index 9d3326e016..0a1448cfbd 100644 --- a/exercises/practice/resistor-color-duo/resistor-color-duo.spec.js +++ b/exercises/practice/resistor-color-duo/resistor-color-duo.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { decodedValue } from './resistor-color-duo'; +import { decodedValue } from './resistor-color-duo.js'; describe('Resistor Colors', () => { test('Brown and black', () => { diff --git a/exercises/practice/resistor-color-trio/resistor-color-trio.spec.js b/exercises/practice/resistor-color-trio/resistor-color-trio.spec.js index 26562bd05b..32c67fae05 100644 --- a/exercises/practice/resistor-color-trio/resistor-color-trio.spec.js +++ b/exercises/practice/resistor-color-trio/resistor-color-trio.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { ResistorColorTrio } from './resistor-color-trio'; +import { ResistorColorTrio } from './resistor-color-trio.js'; function makeLabel({ value, unit }) { return `Resistor value: ${value} ${unit}`; diff --git a/exercises/practice/resistor-color/resistor-color.spec.js b/exercises/practice/resistor-color/resistor-color.spec.js index b9620593a4..32c45d55d5 100644 --- a/exercises/practice/resistor-color/resistor-color.spec.js +++ b/exercises/practice/resistor-color/resistor-color.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { colorCode, COLORS } from './resistor-color'; +import { colorCode, COLORS } from './resistor-color.js'; describe('ResistorColor', () => { describe('Color codes', () => { diff --git a/exercises/practice/rest-api/rest-api.spec.js b/exercises/practice/rest-api/rest-api.spec.js index 5cf19f0f65..9e5490bfd9 100644 --- a/exercises/practice/rest-api/rest-api.spec.js +++ b/exercises/practice/rest-api/rest-api.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { RestAPI } from './rest-api'; +import { RestAPI } from './rest-api.js'; describe('Rest API', () => { describe('user management', () => { diff --git a/exercises/practice/reverse-string/reverse-string.spec.js b/exercises/practice/reverse-string/reverse-string.spec.js index d93cc04e6f..14c02e494c 100644 --- a/exercises/practice/reverse-string/reverse-string.spec.js +++ b/exercises/practice/reverse-string/reverse-string.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { reverseString } from './reverse-string'; +import { reverseString } from './reverse-string.js'; describe('ReverseString', () => { test('empty string', () => { diff --git a/exercises/practice/rna-transcription/rna-transcription.spec.js b/exercises/practice/rna-transcription/rna-transcription.spec.js index 303073fa10..f22596cfad 100644 --- a/exercises/practice/rna-transcription/rna-transcription.spec.js +++ b/exercises/practice/rna-transcription/rna-transcription.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { toRna } from './rna-transcription'; +import { toRna } from './rna-transcription.js'; describe('Transcription', () => { test('empty rna sequence', () => { diff --git a/exercises/practice/robot-name/robot-name.spec.js b/exercises/practice/robot-name/robot-name.spec.js index b6ea732a50..8eb29e311b 100644 --- a/exercises/practice/robot-name/robot-name.spec.js +++ b/exercises/practice/robot-name/robot-name.spec.js @@ -6,7 +6,7 @@ import { test, xtest, } from '@jest/globals'; -import { Robot } from './robot-name'; +import { Robot } from './robot-name.js'; const areSequential = (name1, name2) => { const alpha1 = name1.substring(0, 2); diff --git a/exercises/practice/robot-simulator/robot-simulator.spec.js b/exercises/practice/robot-simulator/robot-simulator.spec.js index a86c31e18f..8fcff4b460 100644 --- a/exercises/practice/robot-simulator/robot-simulator.spec.js +++ b/exercises/practice/robot-simulator/robot-simulator.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { InvalidInputError, Robot } from './robot-simulator'; +import { InvalidInputError, Robot } from './robot-simulator.js'; function turnRight(robot) { robot.evaluate('R'); diff --git a/exercises/practice/roman-numerals/roman-numerals.spec.js b/exercises/practice/roman-numerals/roman-numerals.spec.js index 12bf5a873b..3a12a17a94 100644 --- a/exercises/practice/roman-numerals/roman-numerals.spec.js +++ b/exercises/practice/roman-numerals/roman-numerals.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { toRoman } from './roman-numerals'; +import { toRoman } from './roman-numerals.js'; describe('toRoman()', () => { test('converts 1', () => expect(toRoman(1)).toEqual('I')); diff --git a/exercises/practice/rotational-cipher/rotational-cipher.spec.js b/exercises/practice/rotational-cipher/rotational-cipher.spec.js index 0cf962939d..f74f5820fa 100644 --- a/exercises/practice/rotational-cipher/rotational-cipher.spec.js +++ b/exercises/practice/rotational-cipher/rotational-cipher.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { rotate } from './rotational-cipher'; +import { rotate } from './rotational-cipher.js'; describe('Rotational cipher', () => { test('rotate a by 0, same output as input', () => { diff --git a/exercises/practice/run-length-encoding/run-length-encoding.spec.js b/exercises/practice/run-length-encoding/run-length-encoding.spec.js index a255286c66..bf28f7d40a 100644 --- a/exercises/practice/run-length-encoding/run-length-encoding.spec.js +++ b/exercises/practice/run-length-encoding/run-length-encoding.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { decode, encode } from './run-length-encoding'; +import { decode, encode } from './run-length-encoding.js'; describe('run-length encode a string', () => { test('encode empty string', () => { diff --git a/exercises/practice/saddle-points/saddle-points.spec.js b/exercises/practice/saddle-points/saddle-points.spec.js index f3dc21bb21..721e3cc5d8 100644 --- a/exercises/practice/saddle-points/saddle-points.spec.js +++ b/exercises/practice/saddle-points/saddle-points.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { saddlePoints } from './saddle-points'; +import { saddlePoints } from './saddle-points.js'; describe('Saddle Points', () => { test('Can identify single saddle point', () => { diff --git a/exercises/practice/satellite/satellite.spec.js b/exercises/practice/satellite/satellite.spec.js index e120338463..320624691d 100644 --- a/exercises/practice/satellite/satellite.spec.js +++ b/exercises/practice/satellite/satellite.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { treeFromTraversals } from './satellite'; +import { treeFromTraversals } from './satellite.js'; describe('Satellite', () => { test('Empty tree', () => { diff --git a/exercises/practice/say/say.spec.js b/exercises/practice/say/say.spec.js index 01504764c1..8521102654 100644 --- a/exercises/practice/say/say.spec.js +++ b/exercises/practice/say/say.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { say } from './say'; +import { say } from './say.js'; describe('say', () => { test('zero', () => { diff --git a/exercises/practice/scale-generator/scale-generator.spec.js b/exercises/practice/scale-generator/scale-generator.spec.js index 899ccd1791..0dec8d64a1 100644 --- a/exercises/practice/scale-generator/scale-generator.spec.js +++ b/exercises/practice/scale-generator/scale-generator.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Scale } from './scale-generator'; +import { Scale } from './scale-generator.js'; describe('ScaleGenerator', () => { describe('Chromatic scales', () => { diff --git a/exercises/practice/scrabble-score/scrabble-score.spec.js b/exercises/practice/scrabble-score/scrabble-score.spec.js index e6d2a37724..d97f7bb1b6 100644 --- a/exercises/practice/scrabble-score/scrabble-score.spec.js +++ b/exercises/practice/scrabble-score/scrabble-score.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { score } from './scrabble-score'; +import { score } from './scrabble-score.js'; describe('Scrabble', () => { test('lowercase letter', () => { diff --git a/exercises/practice/secret-handshake/secret-handshake.spec.js b/exercises/practice/secret-handshake/secret-handshake.spec.js index 0b277b93df..d75ba78ccc 100644 --- a/exercises/practice/secret-handshake/secret-handshake.spec.js +++ b/exercises/practice/secret-handshake/secret-handshake.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { commands } from './secret-handshake'; +import { commands } from './secret-handshake.js'; describe('Secret Handshake', () => { describe('Create A Handshake For A Number', () => { diff --git a/exercises/practice/series/series.spec.js b/exercises/practice/series/series.spec.js index 3480e1f9fa..1a2fb7ce8a 100644 --- a/exercises/practice/series/series.spec.js +++ b/exercises/practice/series/series.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Series } from './series'; +import { Series } from './series.js'; describe('Series', () => { test('slices of one from one', () => { diff --git a/exercises/practice/sgf-parsing/.docs/instructions.md b/exercises/practice/sgf-parsing/.docs/instructions.md new file mode 100644 index 0000000000..4e1f59b0dc --- /dev/null +++ b/exercises/practice/sgf-parsing/.docs/instructions.md @@ -0,0 +1,66 @@ +# Instructions + +Your task is to parse a Smart Game Format (SGF) string and return a tree data structure representing the game. + +An SGF string represents a tree of nodes. The entire tree is enclosed in parentheses `()`. +Each node in the tree is denoted by a semicolon `;`, followed by a sequence of properties. +A property consists of an uppercase identifier (e.g., `AB`), followed by one or more values enclosed in brackets `[]`. + +For example, the string `(;FF[4]C[root])` represents a tree with a single root node. That node has two properties: +- Property `FF` with a value of `4` +- Property `C` with a value of `root` + +**Variations (Trees and Branches)** +SGF supports game variations by nesting trees. A tree can have multiple child trees, which are also enclosed in parentheses. +For example, `(;A[B](;C[D])(;E[F]))` represents a root node with property `A`, which has two child branches: +1. A node with property `C` and value `D` +2. A node with property `E` and value `F` + +**Formatting & Escaping** +Values within brackets can contain escaped characters. A backslash `\` followed by any character represents that literal character (e.g., `\]` should be parsed as a literal `]`). Additionally, if a newline is preceded by a backslash, it acts as a line continuation and should be removed from the value. All other newlines within a value should be preserved. + +**Error Handling** +You must throw an error for invalid SGF strings. The following are examples of invalid SGF: +- A tree that does not start with parentheses `()`. +- A node that does not start with a semicolon `;`. +- Property identifiers that are not entirely uppercase letters. +- Missing brackets or mismatched parentheses. + +### Data Structure + +Your parsing function should return a representation of the tree. A common approach is to represent each tree as an object with two fields: +- `properties`: An object (or Map) where the keys are the property identifiers (strings) and the values are arrays of strings (since a property can have multiple values). +- `children`: An array containing the child trees. + + +Example: + +Input: `(;FF[4]C[root])` +Output: `{ + properties: { + FF: ['4'], + C: ['root'] + }, + children: [] +}` + +Input: `(;A[B](;C[D])(;E[F]))` +Output: `{ + properties: { + A: ['B'] + }, + children: [ + { + properties: { + C: ['D'] + }, + children: [] + }, + { + properties: { + E: ['F'] + }, + children: [] + } + ] +}` diff --git a/exercises/practice/sgf-parsing/.docs/introduction.md b/exercises/practice/sgf-parsing/.docs/introduction.md new file mode 100644 index 0000000000..c1d051e45c --- /dev/null +++ b/exercises/practice/sgf-parsing/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +SGF (Smart Game Format) is a popular, text-based file format used for storing records of board games. While it can be used for many different games like Chess, Othello, and Backgammon, it is most widely known and used for the game of Go. + +An SGF file is structured as a tree of nodes. This tree structure is particularly useful because it allows game records to branch out, meaning you can store the main sequence of moves as well as alternative variations, analyses, and commentary all in the same file. + +Each node in the tree contains a set of properties, and each property has one or more values. These properties encode everything from the players' names and ranks, to the game result, board size, and individual moves placed on the board. diff --git a/exercises/practice/sgf-parsing/.gitignore b/exercises/practice/sgf-parsing/.gitignore new file mode 100644 index 0000000000..0c88ff6ec3 --- /dev/null +++ b/exercises/practice/sgf-parsing/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/bin/configlet +/bin/configlet.exe +/package-lock.json +/yarn.lock diff --git a/exercises/practice/sgf-parsing/.meta/config.json b/exercises/practice/sgf-parsing/.meta/config.json new file mode 100644 index 0000000000..26416d4677 --- /dev/null +++ b/exercises/practice/sgf-parsing/.meta/config.json @@ -0,0 +1,24 @@ +{ + "authors": [ + "matthewmorgan" + ], + "files": { + "solution": [ + "sgf-parsing.js" + ], + "test": [ + "sgf-parsing.spec.js" + ], + "example": [ + ".meta/proof.ci.js" + ] + }, + "blurb": "Parsing a Smart Game Format string.", + "source_url": "https://en.wikipedia.org/wiki/Smart_Game_Format", + "custom": { + "version.tests.compatibility": "jest-27", + "flag.tests.task-per-describe": false, + "flag.tests.may-run-long": false, + "flag.tests.includes-optional": false + } +} diff --git a/exercises/practice/sgf-parsing/.meta/proof.ci.js b/exercises/practice/sgf-parsing/.meta/proof.ci.js new file mode 100644 index 0000000000..8885132c54 --- /dev/null +++ b/exercises/practice/sgf-parsing/.meta/proof.ci.js @@ -0,0 +1,132 @@ +export function parse(input) { + if (!input.startsWith('(')) { + throw new Error('tree missing'); + } + + const parser = new SgfParser(input); + return parser.parseTree(); +} + +class SgfParser { + constructor(input) { + this.input = input; + this.pos = 0; + } + + peek() { + return this.input[this.pos]; + } + + consume() { + return this.input[this.pos++]; + } + + parseTree() { + if (this.peek() !== '(') { + throw new Error('tree missing'); + } + this.consume(); // consume '(' + + if (this.peek() === ')') { + throw new Error('tree with no nodes'); + } + + const root = this.parseNode(); + + this.consume(); // consume ')' + + return root; + } + + parseNode() { + if (this.peek() !== ';') { + throw new Error('tree missing'); + } + this.consume(); // consume ';' + + const node = { properties: {}, children: [] }; + + // Parse properties of this node + while (this.pos < this.input.length && /[A-Za-z]/.test(this.peek())) { + const { key, values } = this.parseProperty(); + node.properties[key] = values; + } + + // Parse subsequent nodes or child trees + while (this.pos < this.input.length && this.peek() !== ')') { + if (this.peek() === ';') { + // Next node in sequence becomes the single child + const child = this.parseNode(); + node.children.push(child); + break; // parseNode handles its own children recursively + } else if (this.peek() === '(') { + // Variation: a child tree + const child = this.parseTree(); + node.children.push(child); + } else { + break; + } + } + + return node; + } + + parseProperty() { + let key = ''; + + // Read key characters (must be uppercase letters) + while (this.pos < this.input.length && /[A-Za-z]/.test(this.peek())) { + key += this.consume(); + } + + if (!/^[A-Z]+$/.test(key)) { + throw new Error('property must be in uppercase'); + } + + if (this.peek() !== '[') { + throw new Error('properties without delimiter'); + } + + const values = []; + + // A property can have multiple values: KEY[val1][val2]... + while (this.peek() === '[') { + this.consume(); // consume '[' + values.push(this.parseValue()); + this.consume(); // consume ']' + } + + return { key, values }; + } + + parseValue() { + let value = ''; + + while (this.pos < this.input.length && this.peek() !== ']') { + const ch = this.consume(); + + if (ch === '\\') { + const next = this.consume(); + if (next === '\n') { + // escaped newline: remove entirely + } else if (next === '\r') { + // handle \r\n + if (this.peek() === '\n') this.consume(); + } else if (next === '\t') { + // escaped tab -> space + value += ' '; + } else { + // any other escaped char: keep the char, drop the backslash + value += next; + } + } else if (ch === '\t') { + // unescaped tab -> space + value += ' '; + } else { + value += ch; + } + } + + return value; + } +} diff --git a/exercises/practice/sgf-parsing/.meta/tests.toml b/exercises/practice/sgf-parsing/.meta/tests.toml new file mode 100644 index 0000000000..2a9d7d927b --- /dev/null +++ b/exercises/practice/sgf-parsing/.meta/tests.toml @@ -0,0 +1,84 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[2668d5dc-109f-4f71-b9d5-8d06b1d6f1cd] +description = "empty input" + +[84ded10a-94df-4a30-9457-b50ccbdca813] +description = "tree with no nodes" + +[0a6311b2-c615-4fa7-800e-1b1cbb68833d] +description = "node without tree" + +[8c419ed8-28c4-49f6-8f2d-433e706110ef] +description = "node without properties" + +[8209645f-32da-48fe-8e8f-b9b562c26b49] +description = "single node tree" + +[6c995856-b919-4c75-8fd6-c2c3c31b37dc] +description = "multiple properties" + +[a771f518-ec96-48ca-83c7-f8d39975645f] +description = "properties without delimiter" + +[6c02a24e-6323-4ed5-9962-187d19e36bc8] +description = "all lowercase property" + +[8772d2b1-3c57-405a-93ac-0703b671adc1] +description = "upper and lowercase property" + +[a759b652-240e-42ec-a6d2-3a08d834b9e2] +description = "two nodes" + +[cc7c02bc-6097-42c4-ab88-a07cb1533d00] +description = "two child trees" + +[724eeda6-00db-41b1-8aa9-4d5238ca0130] +description = "multiple property values" + +[28092c06-275f-4b9f-a6be-95663e69d4db] +description = "within property values, whitespace characters such as tab are converted to spaces" + +[deaecb9d-b6df-4658-aa92-dcd70f4d472a] +description = "within property values, newlines remain as newlines" + +[8e4c970e-42d7-440e-bfef-5d7a296868ef] +description = "escaped closing bracket within property value becomes just a closing bracket" + +[cf371fa8-ba4a-45ec-82fb-38668edcb15f] +description = "escaped backslash in property value becomes just a backslash" + +[dc13ca67-fac0-4b65-b3fe-c584d6a2c523] +description = "opening bracket within property value doesn't need to be escaped" + +[a780b97e-8dbb-474e-8f7e-4031902190e8] +description = "semicolon in property value doesn't need to be escaped" + +[0b57a79e-8d89-49e5-82b6-2eaaa6b88ed7] +description = "parentheses in property value don't need to be escaped" + +[c72a33af-9e04-4cc5-9890-1b92262813ac] +description = "escaped tab in property value is converted to space" + +[3a1023d2-7484-4498-8d73-3666bb386e81] +description = "escaped newline in property value is converted to nothing at all" + +[25abf1a4-5205-46f1-8c72-53273b94d009] +description = "escaped t and n in property value are just letters, not whitespace" + +[08e4b8ba-bb07-4431-a3d9-b1f4cdea6dab] +description = "mixing various kinds of whitespace and escaped characters in property value" +reimplements = "11c36323-93fc-495d-bb23-c88ee5844b8c" + +[11c36323-93fc-495d-bb23-c88ee5844b8c] +description = "escaped property" +include = false diff --git a/exercises/practice/sgf-parsing/.npmrc b/exercises/practice/sgf-parsing/.npmrc new file mode 100644 index 0000000000..d26df800bb --- /dev/null +++ b/exercises/practice/sgf-parsing/.npmrc @@ -0,0 +1 @@ +audit=false diff --git a/exercises/practice/sgf-parsing/LICENSE b/exercises/practice/sgf-parsing/LICENSE new file mode 100644 index 0000000000..90e73be03b --- /dev/null +++ b/exercises/practice/sgf-parsing/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Exercism + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/exercises/practice/sgf-parsing/babel.config.js b/exercises/practice/sgf-parsing/babel.config.js new file mode 100644 index 0000000000..a638497df1 --- /dev/null +++ b/exercises/practice/sgf-parsing/babel.config.js @@ -0,0 +1,4 @@ +module.exports = { + presets: [['@exercism/babel-preset-javascript', { corejs: '3.40' }]], + plugins: [], +}; diff --git a/exercises/practice/sgf-parsing/eslint.config.mjs b/exercises/practice/sgf-parsing/eslint.config.mjs new file mode 100644 index 0000000000..ca517111ed --- /dev/null +++ b/exercises/practice/sgf-parsing/eslint.config.mjs @@ -0,0 +1,45 @@ +// @ts-check + +import config from '@exercism/eslint-config-javascript'; +import maintainersConfig from '@exercism/eslint-config-javascript/maintainers.mjs'; + +import globals from 'globals'; + +export default [ + ...config, + ...maintainersConfig, + { + files: maintainersConfig[1].files, + rules: { + 'jest/expect-expect': ['warn', { assertFunctionNames: ['expect*'] }], + }, + }, + { + files: ['scripts/**/*.mjs'], + languageOptions: { + globals: { + ...globals.node, + }, + }, + }, + // <> + { + ignores: [ + // # Protected or generated + '/.appends/**/*', + '/.github/**/*', + '/.vscode/**/*', + + // # Binaries + '/bin/*', + + // # Configuration + '/config', + '/babel.config.js', + + // # Typings + '/exercises/**/global.d.ts', + '/exercises/**/env.d.ts', + ], + }, +]; diff --git a/exercises/practice/sgf-parsing/example.js b/exercises/practice/sgf-parsing/example.js new file mode 100644 index 0000000000..8885132c54 --- /dev/null +++ b/exercises/practice/sgf-parsing/example.js @@ -0,0 +1,132 @@ +export function parse(input) { + if (!input.startsWith('(')) { + throw new Error('tree missing'); + } + + const parser = new SgfParser(input); + return parser.parseTree(); +} + +class SgfParser { + constructor(input) { + this.input = input; + this.pos = 0; + } + + peek() { + return this.input[this.pos]; + } + + consume() { + return this.input[this.pos++]; + } + + parseTree() { + if (this.peek() !== '(') { + throw new Error('tree missing'); + } + this.consume(); // consume '(' + + if (this.peek() === ')') { + throw new Error('tree with no nodes'); + } + + const root = this.parseNode(); + + this.consume(); // consume ')' + + return root; + } + + parseNode() { + if (this.peek() !== ';') { + throw new Error('tree missing'); + } + this.consume(); // consume ';' + + const node = { properties: {}, children: [] }; + + // Parse properties of this node + while (this.pos < this.input.length && /[A-Za-z]/.test(this.peek())) { + const { key, values } = this.parseProperty(); + node.properties[key] = values; + } + + // Parse subsequent nodes or child trees + while (this.pos < this.input.length && this.peek() !== ')') { + if (this.peek() === ';') { + // Next node in sequence becomes the single child + const child = this.parseNode(); + node.children.push(child); + break; // parseNode handles its own children recursively + } else if (this.peek() === '(') { + // Variation: a child tree + const child = this.parseTree(); + node.children.push(child); + } else { + break; + } + } + + return node; + } + + parseProperty() { + let key = ''; + + // Read key characters (must be uppercase letters) + while (this.pos < this.input.length && /[A-Za-z]/.test(this.peek())) { + key += this.consume(); + } + + if (!/^[A-Z]+$/.test(key)) { + throw new Error('property must be in uppercase'); + } + + if (this.peek() !== '[') { + throw new Error('properties without delimiter'); + } + + const values = []; + + // A property can have multiple values: KEY[val1][val2]... + while (this.peek() === '[') { + this.consume(); // consume '[' + values.push(this.parseValue()); + this.consume(); // consume ']' + } + + return { key, values }; + } + + parseValue() { + let value = ''; + + while (this.pos < this.input.length && this.peek() !== ']') { + const ch = this.consume(); + + if (ch === '\\') { + const next = this.consume(); + if (next === '\n') { + // escaped newline: remove entirely + } else if (next === '\r') { + // handle \r\n + if (this.peek() === '\n') this.consume(); + } else if (next === '\t') { + // escaped tab -> space + value += ' '; + } else { + // any other escaped char: keep the char, drop the backslash + value += next; + } + } else if (ch === '\t') { + // unescaped tab -> space + value += ' '; + } else { + value += ch; + } + } + + return value; + } +} diff --git a/exercises/practice/sgf-parsing/jest.config.js b/exercises/practice/sgf-parsing/jest.config.js new file mode 100644 index 0000000000..ec8e908127 --- /dev/null +++ b/exercises/practice/sgf-parsing/jest.config.js @@ -0,0 +1,22 @@ +module.exports = { + verbose: true, + projects: [''], + testMatch: [ + '**/__tests__/**/*.[jt]s?(x)', + '**/test/**/*.[jt]s?(x)', + '**/?(*.)+(spec|test).[jt]s?(x)', + ], + testPathIgnorePatterns: [ + '/(?:production_)?node_modules/', + '.d.ts$', + '/test/fixtures', + '/test/helpers', + '__mocks__', + ], + transform: { + '^.+\\.[jt]sx?$': 'babel-jest', + }, + moduleNameMapper: { + '^(\\.\\/.+)\\.js$': '$1', + }, +}; diff --git a/exercises/practice/sgf-parsing/package.json b/exercises/practice/sgf-parsing/package.json new file mode 100644 index 0000000000..61f58364f4 --- /dev/null +++ b/exercises/practice/sgf-parsing/package.json @@ -0,0 +1,38 @@ +{ + "name": "@exercism/javascript-practice-sgf-parsing", + "description": "Exercism practice exercise on sgf-parsing", + "author": "Katrina Owen", + "contributors": [ + "Derk-Jan Karrenbeld (https://derk-jan.com)", + "Tejas Bubane (https://tejasbubane.github.io/)" + ], + "private": true, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/exercism/javascript", + "directory": "exercises/practice/sgf-parsing" + }, + "devDependencies": { + "@exercism/babel-preset-javascript": "^0.5.1", + "@exercism/eslint-config-javascript": "^0.8.1", + "@jest/globals": "^30.3.0", + "@types/node": "^24.3.0", + "@types/shelljs": "^0.8.17", + "babel-jest": "^30.3.0", + "core-js": "~3.46.0", + "diff": "^8.0.3", + "eslint": "^9.28.0", + "expect": "^29.7.0", + "globals": "^16.3.0", + "jest": "^30.2.0" + }, + "dependencies": {}, + "scripts": { + "lint": "corepack pnpm eslint .", + "test": "corepack pnpm jest", + "watch": "corepack pnpm jest --watch", + "format": "corepack pnpm prettier -w ." + }, + "packageManager": "pnpm@9.15.2" +} diff --git a/exercises/practice/sgf-parsing/sgf-parsing.js b/exercises/practice/sgf-parsing/sgf-parsing.js new file mode 100644 index 0000000000..c6bb9e6937 --- /dev/null +++ b/exercises/practice/sgf-parsing/sgf-parsing.js @@ -0,0 +1,8 @@ +// +// This is only a SKELETON file for the 'sgf-parsing' exercise. It's been provided as a +// convenience to get you started writing code faster. +// + +export const parse = () => { + throw new Error('Remove this line and implement the function'); +}; diff --git a/exercises/practice/sgf-parsing/sgf-parsing.spec.js b/exercises/practice/sgf-parsing/sgf-parsing.spec.js new file mode 100644 index 0000000000..324bd9661c --- /dev/null +++ b/exercises/practice/sgf-parsing/sgf-parsing.spec.js @@ -0,0 +1,158 @@ +import { describe, expect, test, xtest } from '@jest/globals'; +import { parse } from './sgf-parsing'; + +describe('Sgf Parsing', () => { + test('empty input', () => { + expect(() => parse('')).toThrow('tree missing'); + }); + + xtest('tree with no nodes', () => { + expect(() => parse('()')).toThrow('tree with no nodes'); + }); + + xtest('node without tree', () => { + expect(() => parse(';')).toThrow('tree missing'); + }); + + xtest('node without properties', () => { + expect(parse('(;)')).toEqual({ properties: {}, children: [] }); + }); + + xtest('single node tree', () => { + expect(parse('(;A[B])')).toEqual({ + properties: { A: ['B'] }, + children: [], + }); + }); + + xtest('multiple properties', () => { + expect(parse('(;A[b]C[d])')).toEqual({ + properties: { A: ['b'], C: ['d'] }, + children: [], + }); + }); + + xtest('properties without delimiter', () => { + expect(() => parse('(;A)')).toThrow('properties without delimiter'); + }); + + xtest('all lowercase property', () => { + expect(() => parse('(;a[b])')).toThrow('property must be in uppercase'); + }); + + xtest('upper and lowercase property', () => { + expect(() => parse('(;Aa[b])')).toThrow('property must be in uppercase'); + }); + + xtest('two nodes', () => { + expect(parse('(;A[B];B[C])')).toEqual({ + properties: { A: ['B'] }, + children: [ + { + properties: { B: ['C'] }, + children: [], + }, + ], + }); + }); + + xtest('two child trees', () => { + expect(parse('(;A[B](;B[C])(;C[D]))')).toEqual({ + properties: { A: ['B'] }, + children: [ + { + properties: { B: ['C'] }, + children: [], + }, + { + properties: { C: ['D'] }, + children: [], + }, + ], + }); + }); + + xtest('multiple property values', () => { + expect(parse('(;A[b][c][d])')).toEqual({ + properties: { A: ['b', 'c', 'd'] }, + children: [], + }); + }); + + xtest('within property values, whitespace characters such as tab are converted to spaces', () => { + expect(parse('(;A[hello\t\tworld])')).toEqual({ + properties: { A: ['hello world'] }, + children: [], + }); + }); + + xtest('within property values, newlines remain as newlines', () => { + expect(parse('(;A[hello\n\nworld])')).toEqual({ + properties: { A: ['hello\n\nworld'] }, + children: [], + }); + }); + + xtest('escaped closing bracket within property value becomes just a closing bracket', () => { + expect(parse('(;A[\\]])')).toEqual({ + properties: { A: [']'] }, + children: [], + }); + }); + + xtest('escaped backslash in property value becomes just a backslash', () => { + expect(parse('(;A[\\\\])')).toEqual({ + properties: { A: ['\\'] }, + children: [], + }); + }); + + xtest("opening bracket within property value doesn't need to be escaped", () => { + expect(parse('(;A[b[c])')).toEqual({ + properties: { A: ['b[c'] }, + children: [], + }); + }); + + xtest("semicolon in property value doesn't need to be escaped", () => { + expect(parse('(;A[a;b])')).toEqual({ + properties: { A: ['a;b'] }, + children: [], + }); + }); + + xtest("parentheses in property value don't need to be escaped", () => { + expect(parse('(;A[a(b])')).toEqual({ + properties: { A: ['a(b'] }, + children: [], + }); + }); + + xtest('escaped tab in property value is converted to space', () => { + expect(parse('(;A[\\\t])')).toEqual({ + properties: { A: [' '] }, + children: [], + }); + }); + + xtest('escaped newline in property value is converted to nothing at all', () => { + expect(parse('(;A[\\\n])')).toEqual({ + properties: { A: [''] }, + children: [], + }); + }); + + xtest('escaped t and n in property value are just letters, not whitespace', () => { + expect(parse('(;A[\\t][\\n])')).toEqual({ + properties: { A: ['t', 'n'] }, + children: [], + }); + }); + + xtest('mixing various kinds of whitespace and escaped characters in property value', () => { + expect(parse('(;A[\\]b\nc\\\nd\t\te\\\\ \\\n\\]])')).toEqual({ + properties: { A: [']b\ncd e\\ ]'] }, + children: [], + }); + }); +}); diff --git a/exercises/practice/sieve/sieve.spec.js b/exercises/practice/sieve/sieve.spec.js index 2a8f382a3f..af2aa8a7ed 100644 --- a/exercises/practice/sieve/sieve.spec.js +++ b/exercises/practice/sieve/sieve.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { primes } from './sieve'; +import { primes } from './sieve.js'; describe('Sieve', () => { test('no primes under two', () => { diff --git a/exercises/practice/simple-cipher/simple-cipher.spec.js b/exercises/practice/simple-cipher/simple-cipher.spec.js index b9b98b0860..86eb62f1ba 100644 --- a/exercises/practice/simple-cipher/simple-cipher.spec.js +++ b/exercises/practice/simple-cipher/simple-cipher.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Cipher } from './simple-cipher'; +import { Cipher } from './simple-cipher.js'; describe('Random key cipher', () => { const cipher = new Cipher(); diff --git a/exercises/practice/simple-linked-list/simple-linked-list.spec.js b/exercises/practice/simple-linked-list/simple-linked-list.spec.js index 99d8c0300b..0d32e06bd7 100644 --- a/exercises/practice/simple-linked-list/simple-linked-list.spec.js +++ b/exercises/practice/simple-linked-list/simple-linked-list.spec.js @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, test, xtest } from '@jest/globals'; -import { Element, List } from './simple-linked-list'; +import { Element, List } from './simple-linked-list.js'; describe('Element class', () => { test('has constructor', () => { diff --git a/exercises/practice/space-age/space-age.spec.js b/exercises/practice/space-age/space-age.spec.js index 84c4e4449f..9ea3b52a81 100644 --- a/exercises/practice/space-age/space-age.spec.js +++ b/exercises/practice/space-age/space-age.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { age } from './space-age'; +import { age } from './space-age.js'; describe('Space Age', () => { test('age on Earth', () => { diff --git a/exercises/practice/spiral-matrix/spiral-matrix.spec.js b/exercises/practice/spiral-matrix/spiral-matrix.spec.js index 8486f70b68..a511072ff2 100644 --- a/exercises/practice/spiral-matrix/spiral-matrix.spec.js +++ b/exercises/practice/spiral-matrix/spiral-matrix.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { spiralMatrix } from './spiral-matrix'; +import { spiralMatrix } from './spiral-matrix.js'; describe('Spiral Matrix', () => { test('empty spiral', () => { diff --git a/exercises/practice/split-second-stopwatch/split-second-stopwatch.spec.js b/exercises/practice/split-second-stopwatch/split-second-stopwatch.spec.js index a782550840..b40a4a186c 100644 --- a/exercises/practice/split-second-stopwatch/split-second-stopwatch.spec.js +++ b/exercises/practice/split-second-stopwatch/split-second-stopwatch.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { SplitSecondStopwatch } from './split-second-stopwatch'; +import { SplitSecondStopwatch } from './split-second-stopwatch.js'; describe('SplitSecondStopwatch', () => { test('new stopwatch starts in ready state', () => { diff --git a/exercises/practice/square-root/square-root.spec.js b/exercises/practice/square-root/square-root.spec.js index fc59e70947..30d7799959 100644 --- a/exercises/practice/square-root/square-root.spec.js +++ b/exercises/practice/square-root/square-root.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { squareRoot } from './square-root'; +import { squareRoot } from './square-root.js'; describe('Square root', () => { test('root of 1', () => { diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/proof.ci.js b/exercises/practice/state-of-tic-tac-toe/.meta/proof.ci.js index ac6750df6d..9d774d25ae 100644 --- a/exercises/practice/state-of-tic-tac-toe/.meta/proof.ci.js +++ b/exercises/practice/state-of-tic-tac-toe/.meta/proof.ci.js @@ -27,7 +27,8 @@ export const gamestate = (board) => { throw new Error('Wrong turn order: X went twice'); case numberOfX - numberOfO < 0: throw new Error('Wrong turn order: O started'); - case scorringArray.includes(gridSize) && scorringArray.includes(-gridSize): + case (scorringArray.includes(gridSize) && numberOfX === numberOfO) || + (scorringArray.includes(-gridSize) && numberOfX > numberOfO): throw new Error( 'Impossible board: game should have ended after the game was won', ); diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml b/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml index 8fc25e2118..5f574b2a12 100644 --- a/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml +++ b/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml @@ -99,3 +99,9 @@ reimplements = "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d" [4801cda2-f5b7-4c36-8317-3cdd167ac22c] description = "Invalid boards -> Invalid board: players kept playing after a win" + +[5a84757a-fc86-4328-aec9-a5759e6ed35d] +description = "Invalid boards -> Invalid board: O kept playing after X wins" + +[cf25543d-583a-4656-b9ab-f82dc00a4a02] +description = "Invalid boards -> Invalid board: X kept playing after O wins" diff --git a/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe.spec.js b/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe.spec.js index d6cdda3750..c4f7b2c13e 100644 --- a/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe.spec.js +++ b/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { gamestate } from './state-of-tic-tac-toe'; +import { gamestate } from './state-of-tic-tac-toe.js'; describe('Won games', () => { test('Finished game where X won via left column victory', () => { @@ -200,4 +200,22 @@ describe('Invalid boards', () => { const actual = () => gamestate(board); expect(actual).toThrow(expected); }); + + xtest('Invalid board: O kept playing after X wins', () => { + const board = ['OO ', 'XXX', ' O ']; + const expected = new Error( + 'Impossible board: game should have ended after the game was won', + ); + const actual = () => gamestate(board); + expect(actual).toThrow(expected); + }); + + xtest('Invalid board: X kept playing after O wins', () => { + const board = ['XX ', 'OOO', ' XX']; + const expected = new Error( + 'Impossible board: game should have ended after the game was won', + ); + const actual = () => gamestate(board); + expect(actual).toThrow(expected); + }); }); diff --git a/exercises/practice/strain/strain.spec.js b/exercises/practice/strain/strain.spec.js index 875b0e3338..f817778637 100644 --- a/exercises/practice/strain/strain.spec.js +++ b/exercises/practice/strain/strain.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { discard, keep } from './strain'; +import { discard, keep } from './strain.js'; describe('strain', () => { test('keeps on empty array returns empty array', () => { diff --git a/exercises/practice/sublist/.meta/config.json b/exercises/practice/sublist/.meta/config.json index 502e8e0c84..3cc4445b5f 100644 --- a/exercises/practice/sublist/.meta/config.json +++ b/exercises/practice/sublist/.meta/config.json @@ -22,7 +22,7 @@ ".meta/proof.ci.js" ] }, - "blurb": "Write a function to determine if a list is a sublist of another list.", + "blurb": "Determine if a list is a sublist of another list.", "custom": { "version.tests.compatibility": "jest-27", "flag.tests.task-per-describe": false, diff --git a/exercises/practice/sublist/sublist.spec.js b/exercises/practice/sublist/sublist.spec.js index e290fc1de9..9adeaaede6 100644 --- a/exercises/practice/sublist/sublist.spec.js +++ b/exercises/practice/sublist/sublist.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { List } from './sublist'; +import { List } from './sublist.js'; describe('sublist', () => { test('two empty lists are equal', () => { diff --git a/exercises/practice/sum-of-multiples/sum-of-multiples.spec.js b/exercises/practice/sum-of-multiples/sum-of-multiples.spec.js index d824231a7a..c16b231be2 100644 --- a/exercises/practice/sum-of-multiples/sum-of-multiples.spec.js +++ b/exercises/practice/sum-of-multiples/sum-of-multiples.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { sum } from './sum-of-multiples'; +import { sum } from './sum-of-multiples.js'; describe('Sum Of Multiples', () => { test('no multiples within limit', () => { diff --git a/exercises/practice/tournament/tournament.spec.js b/exercises/practice/tournament/tournament.spec.js index 9cb53d5f64..7473dc0a23 100644 --- a/exercises/practice/tournament/tournament.spec.js +++ b/exercises/practice/tournament/tournament.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { tournamentTally } from './tournament'; +import { tournamentTally } from './tournament.js'; describe('Tournament', () => { test('just the header if no input', () => { diff --git a/exercises/practice/transpose/transpose.spec.js b/exercises/practice/transpose/transpose.spec.js index ff7e8779ee..62f663c05d 100644 --- a/exercises/practice/transpose/transpose.spec.js +++ b/exercises/practice/transpose/transpose.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { transpose } from './transpose'; +import { transpose } from './transpose.js'; describe('Transpose', () => { test('empty string', () => { diff --git a/exercises/practice/triangle/triangle.spec.js b/exercises/practice/triangle/triangle.spec.js index b8b6cb6110..e20a7ae0d7 100644 --- a/exercises/practice/triangle/triangle.spec.js +++ b/exercises/practice/triangle/triangle.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Triangle } from './triangle'; +import { Triangle } from './triangle.js'; describe('Triangle', () => { describe('equilateral triangle', () => { diff --git a/exercises/practice/trinary/trinary.spec.js b/exercises/practice/trinary/trinary.spec.js index f692226379..cb6f399be4 100644 --- a/exercises/practice/trinary/trinary.spec.js +++ b/exercises/practice/trinary/trinary.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { Trinary } from './trinary'; +import { Trinary } from './trinary.js'; describe('Trinary', () => { test('1 is decimal 1', () => { diff --git a/exercises/practice/twelve-days/twelve-days.spec.js b/exercises/practice/twelve-days/twelve-days.spec.js index 0776467fbf..af4c286bbc 100644 --- a/exercises/practice/twelve-days/twelve-days.spec.js +++ b/exercises/practice/twelve-days/twelve-days.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { recite } from './twelve-days'; +import { recite } from './twelve-days.js'; describe('TwelveDays', () => { test('verse first day a partridge in a pear tree', () => { diff --git a/exercises/practice/two-bucket/two-bucket.spec.js b/exercises/practice/two-bucket/two-bucket.spec.js index dd05397480..1cd9699cce 100644 --- a/exercises/practice/two-bucket/two-bucket.spec.js +++ b/exercises/practice/two-bucket/two-bucket.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { TwoBucket } from './two-bucket'; +import { TwoBucket } from './two-bucket.js'; describe('TwoBucket', () => { describe('Measure using bucket one of size 3 and bucket two of size 5', () => { diff --git a/exercises/practice/two-fer/two-fer.spec.js b/exercises/practice/two-fer/two-fer.spec.js index e84c57fed0..06c70cb294 100644 --- a/exercises/practice/two-fer/two-fer.spec.js +++ b/exercises/practice/two-fer/two-fer.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { twoFer } from './two-fer'; +import { twoFer } from './two-fer.js'; describe('twoFer()', () => { test('no name given', () => { diff --git a/exercises/practice/variable-length-quantity/variable-length-quantity.spec.js b/exercises/practice/variable-length-quantity/variable-length-quantity.spec.js index eebf839bd3..270c052405 100644 --- a/exercises/practice/variable-length-quantity/variable-length-quantity.spec.js +++ b/exercises/practice/variable-length-quantity/variable-length-quantity.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { decode, encode } from './variable-length-quantity'; +import { decode, encode } from './variable-length-quantity.js'; describe('VariableLengthQuantity', () => { describe('Encode a series of integers, producing a series of bytes.', () => { diff --git a/exercises/practice/word-count/word-count.spec.js b/exercises/practice/word-count/word-count.spec.js index b83e5043bd..fe42bc490e 100644 --- a/exercises/practice/word-count/word-count.spec.js +++ b/exercises/practice/word-count/word-count.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { countWords } from './word-count'; +import { countWords } from './word-count.js'; describe('countWords', () => { test('count one word', () => { diff --git a/exercises/practice/word-search/word-search.spec.js b/exercises/practice/word-search/word-search.spec.js index aaa5f77795..dedffb5c05 100644 --- a/exercises/practice/word-search/word-search.spec.js +++ b/exercises/practice/word-search/word-search.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import WordSearch from './word-search'; +import WordSearch from './word-search.js'; describe('Word Search', () => { test('Should accept an initial game grid', () => { diff --git a/exercises/practice/wordy/wordy.spec.js b/exercises/practice/wordy/wordy.spec.js index 1be21e3dca..cdb5c73ca2 100644 --- a/exercises/practice/wordy/wordy.spec.js +++ b/exercises/practice/wordy/wordy.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { answer } from './wordy'; +import { answer } from './wordy.js'; describe('Wordy', () => { test('just a number', () => { diff --git a/exercises/practice/yacht/yacht.spec.js b/exercises/practice/yacht/yacht.spec.js index 1800c90d28..d5a05e25f3 100644 --- a/exercises/practice/yacht/yacht.spec.js +++ b/exercises/practice/yacht/yacht.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { score } from './yacht'; +import { score } from './yacht.js'; describe('Yacht', () => { test('Yacht', () => { diff --git a/exercises/practice/zebra-puzzle/zebra-puzzle.spec.js b/exercises/practice/zebra-puzzle/zebra-puzzle.spec.js index e61823d6ac..f320685129 100644 --- a/exercises/practice/zebra-puzzle/zebra-puzzle.spec.js +++ b/exercises/practice/zebra-puzzle/zebra-puzzle.spec.js @@ -1,5 +1,5 @@ import { describe, expect, test, xtest } from '@jest/globals'; -import { ZebraPuzzle } from './zebra-puzzle'; +import { ZebraPuzzle } from './zebra-puzzle.js'; describe('Zebra puzzle', () => { test('resident who drinks water', () => { diff --git a/exercises/practice/zipper/.docs/instructions.md b/exercises/practice/zipper/.docs/instructions.md index 5445db0035..fd401c27e1 100644 --- a/exercises/practice/zipper/.docs/instructions.md +++ b/exercises/practice/zipper/.docs/instructions.md @@ -2,10 +2,15 @@ Creating a zipper for a binary tree. -[Zippers][zipper] are a purely functional way of navigating within a data structure and manipulating it. -They essentially contain a data structure and a pointer into that data structure (called the focus). +[Zippers][zipper] are a purely functional way to navigate and manipulate a data structure. +A zipper is not simply a data structure with a pointer - instead, it consists of two parts: -For example given a rose tree (where each node contains a value and a list of child nodes) a zipper might support these operations: +1. **The path/thread**: The steps taken to reach the focused node (e.g., "go left from root", "go right from there") +2. **The focused subtree**: The current node and everything below it + +From these two parts, the original data structure can be fully reconstructed, and modifications can be made by building new subtrees as you reverse the path. + +For example given a binary tree, a zipper might support these operations: - `from_tree` (get a zipper out of a rose tree, the focus is on the root node) - `to_tree` (get the rose tree out of the zipper) diff --git a/exercises/practice/zipper/zipper.spec.js b/exercises/practice/zipper/zipper.spec.js index df71114441..5ec37cd2c1 100644 --- a/exercises/practice/zipper/zipper.spec.js +++ b/exercises/practice/zipper/zipper.spec.js @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, test, xtest } from '@jest/globals'; -import { Zipper } from './zipper'; +import { Zipper } from './zipper.js'; function bt(value, left, right) { return {