Skip to content

Commit

Permalink
Merge branch 'main' into ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
Cool-Katt authored Mar 23, 2024
2 parents 9d431b5 + 2447138 commit 4978c6b
Show file tree
Hide file tree
Showing 63 changed files with 1,240 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
git checkout -b "$HEAD_REF" "origin/$HEAD_REF"
- name: Use Node.js LTS (18.x)
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: '18'
- name: Install project development dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Use Node.js LTS (18.x)
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: '18'

Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: ${{ matrix.node-version }}

Expand Down
71 changes: 13 additions & 58 deletions .github/workflows/no-important-files-changed.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,23 @@
name: No important files changed

on:
pull_request:
pull_request_target:
types: [opened]
branches: [main]
paths:
- 'exercises/concept/**'
- 'exercises/practice/**'
- '!exercises/*/*/.approaches/**'
- '!exercises/*/*/.articles/**'
- '!exercises/*/*/.docs/**'
- '!exercises/*/*/.meta/**'

permissions:
pull-requests: write

jobs:
no_important_files_changed:
name: No important files changed
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Check if important files changed
id: check
run: |
set -exo pipefail
# fetch a ref to the main branch so we can diff against it
git remote set-branches origin main
git fetch --depth 1 origin main
for changed_file in $(git diff --diff-filter=M --name-only origin/main); do
if ! echo "$changed_file" | grep --quiet --extended-regexp 'exercises/(practice|concept)' ; then
continue
fi
slug="$(echo "$changed_file" | sed --regexp-extended 's#exercises/[^/]+/([^/]+)/.*#\1#' )"
path_before_slug="$(echo "$changed_file" | sed --regexp-extended "s#(.*)/$slug/.*#\\1#" )"
path_after_slug="$( echo "$changed_file" | sed --regexp-extended "s#.*/$slug/(.*)#\\1#" )"
if ! [ -f "$path_before_slug/$slug/.meta/config.json" ]; then
# cannot determine if important files changed without .meta/config.json
continue
fi
# returns 0 if the filter matches, 1 otherwise
# | contains($path_after_slug)
if jq --exit-status \
--arg path_after_slug "$path_after_slug" \
'[.files.test, .files.invalidator, .files.editor] | flatten | index($path_after_slug)' \
"$path_before_slug/$slug/.meta/config.json" \
> /dev/null;
then
echo "important_files_changed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
done
echo "important_files_changed=false" >> "$GITHUB_OUTPUT"
- name: Suggest to add [no important files changed]
if: steps.check.outputs.important_files_changed == 'true'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ github.token }}
script: |
const body = "This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.\n\nIf this PR does **not** affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), **please add the following to the merge-commit message** which will stops student's tests from re-running. Please copy-paste to avoid typos.\n```\n[no important files changed]\n```\n\n For more information, refer to the [documentation](https://exercism.org/docs/building/tracks#h-avoiding-triggering-unnecessary-test-runs). If you are unsure whether to add the message or not, please ping `@exercism/maintainers-admin` in a comment. Thank you!"
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
pause:
uses: exercism/github-actions/.github/workflows/check-no-important-files-changed.yml@main
with:
repository: ${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}
ref: ${{ github.head_ref }}
4 changes: 2 additions & 2 deletions .github/workflows/pr.ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Use Node.js LTS (18.x)
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: '18'

Expand All @@ -40,7 +40,7 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: ${{ matrix.node-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: 'Checkout code'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Use Node.js LTS (18.x)
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: '18'
- name: Install project development dependencies
Expand Down
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ exercises/**/README.md
# Originates from https://github.com/exercism/org-wide-files
CODE_OF_CONDUCT.md
LICENSE
.github/workflows/configlet.yml
.github/workflows/sync-labels.yml
.github/workflows/no-important-files-changed.yml
.github/workflows/pause-community-contributions.yml

# These are formatted via configlet and will not match prettier
exercises/**/.meta/config.json
Expand All @@ -14,4 +18,4 @@ config.json

# Originates from https://github.com/exercism/problem-specifications
exercises/practice/**/.docs/instructions.md
exercises/practice/**/.docs/introduction.md
exercises/practice/**/.docs/introduction.md
72 changes: 71 additions & 1 deletion concepts/recursion/introduction.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
# Introduction

TODO: add introduction for recursion concept
The ability for something to be defined in terms of itself is called recursion.
Recursive functions are functions that call themselves.

Suppose that you have a function called `recurse`.
This function is recursive if it calls itself inside its body, like this:

```js
function recurse() {
// ...
recurse();
// ...
}
```

A recursive function usually has a condition to stop calling itself and return a value, known as a _base case_.
If a base case is missing, in most cases, because it will call itself indefinitely, it would be able to run forever.
In reality, in most of those situations, you'll end up with a "StackSize error": an error raised by the runtime because the _stack_ of function calls has grown beyond a predefined limit because each recursive call adds to this _stack_ until it returns (and it doesn't).
The message of this error is `Maximum call stack size exceeded`.

```js
function recurse() {
if (baseCondition) {
// stop calling itself
//...
} else {
recurse();
}
}
```

Recursive functions often can be used instead of `for` loops for more succinct code.
For example, take a countdown.
Here's the more intuitive `for` loop approach:

```js
function countDown(fromNumber) {
for (let i = fromNumber; i > 0; i--) {
console.log(i);
}
}

countDown(3); // 3, 2, 1 in separate lines
```

We could solve this using recursion too:

```js
function countDown(fromNumber) {
console.log(fromNumber);
if (fromNumber > 1) {
countDown(fromNumber - 1);
}
}

countDown(3); // same result
```

Here, our base case is when `fromNumber` is 1, in which case we don't call `countDown` again.

Apart from just displaying numbers, recursive functions can be used for more complicated procedures, such as keeping a sum or total.

```js
function sum(n) {
if (n <= 1) {
return n;
}
return n + sum(n - 1);
}

sum(3); // 6
```
27 changes: 22 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,7 @@
"difficulty": 7
},
{
"slug": "pop-count",
"slug": "eliuds-eggs",
"name": "Eliud's Eggs",
"uuid": "2a3ecf62-fb5d-4dac-8369-72e7976a8f57",
"practices": [],
Expand Down Expand Up @@ -2579,17 +2579,34 @@
]
},
{
"slug": "ledger",
"name": "Ledger",
"uuid": "8716b347-e18f-48a6-b373-426cc4ca98cb",
"slug": "markdown",
"name": "Markdown",
"uuid": "cd666b3a-7114-4ba9-9b2a-7622a2c8c12c",
"practices": [
"strings",
"string-formatting"
],
"prerequisites": [],
"difficulty": 5
},
{
"slug": "micro-blog",
"name": "Micro Blog",
"uuid": "ee771d09-33fb-4450-b9c3-d591a4a90a99",
"practices": [],
"prerequisites": [
"strings"
],
"difficulty": 2
},
{
"slug": "ledger",
"name": "Ledger",
"uuid": "8716b347-e18f-48a6-b373-426cc4ca98cb",
"prerequisites": [
"string-formatting"
],
"difficulty": 4
"difficulty": 5
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/lasagna/lasagna.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ describe('totalTimeInMinutes', () => {
test('calculates the total cooking time', () => {
expect(totalTimeInMinutes(1, 5)).toBe(7);
expect(totalTimeInMinutes(4, 15)).toBe(23);
expect(totalTimeInMinutes(1, 35)).toBe(37);
expect(totalTimeInMinutes(1, 30)).toBe(32);
});
});
2 changes: 1 addition & 1 deletion exercises/concept/pizza-order/pizza-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function pizzaPrice(pizza, ...extras) {
}

/**
* Calculate the prize of the total order, given individual orders
* Calculate the price of the total order, given individual orders
*
* @param {PizzaOrder[]} pizzaOrders a list of pizza orders
* @returns {number} the price of the total order
Expand Down
6 changes: 3 additions & 3 deletions exercises/concept/regular-chatbot/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ The Chatbot is a really curious software. Even though he can search on the inter
Example of Conversation:
- **Chatbot**: Hey username, I would like to learn how to code in JavaScript, do you know any cool website where I could learn?
- **User**: I learned a lot from [exercism.com](http://website.com)
- **User**: I learned a lot from [exercism.org](http://exercism.org)
Implement the function `getURL()` which is able to return an array with just the link of each website.
```javascript
getURL('I learned a lot from exercism.com');
// => ["exercism.com"];
getURL('I learned a lot from exercism.org');
// => ["exercism.org"];
```
## Greet the user
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/translation-service/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ExternalApi {

if (typeof callback !== 'function') {
throw new BadRequest(
`Expected callback function when calling fetch(text, callback), actual ${typeof callback}.`,
`Expected callback function when calling request(text, callback), actual ${typeof callback}.`,
);
}

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
],
"files": {
"solution": [
"pop-count.js"
"eliuds-eggs.js"
],
"test": [
"pop-count.spec.js"
"eliuds-eggs.spec.js"
],
"example": [
".meta/proof.ci.js"
]
},
"blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.",
"source": "Christian Willner, Eric Willigers",
"source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5"
"source_url": "https://forum.exercism.org/t/new-exercise-suggestion-eliuds-eggs/7632/5"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { eggCount } from './pop-count';
import { eggCount } from './eliuds-eggs';

describe('PopCount', () => {
describe('EliudsEggs', () => {
test('0 eggs', () => {
const expected = 0;
const actual = eggCount(0);
Expand Down
34 changes: 34 additions & 0 deletions exercises/practice/eliuds-eggs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@exercism/javascript-eliuds-eggs",
"description": "Exercism practice exercise on eliuds-eggs",
"author": "Katrina Owen",
"contributors": [
"Cool-Katt (https://github.com/Cool-Katt)",
"Derk-Jan Karrenbeld <[email protected]> (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/eliuds-eggs"
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@exercism/babel-preset-javascript": "^0.2.1",
"@exercism/eslint-config-javascript": "^0.6.0",
"@types/jest": "^29.5.4",
"@types/node": "^20.5.6",
"babel-jest": "^29.6.4",
"core-js": "~3.32.2",
"eslint": "^8.49.0",
"jest": "^29.7.0"
},
"dependencies": {},
"scripts": {
"test": "jest ./*",
"watch": "jest --watch ./*",
"lint": "eslint ."
}
}
13 changes: 13 additions & 0 deletions exercises/practice/markdown/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Instructions

Refactor a Markdown parser.

The markdown exercise is a refactoring exercise.
There is code that parses a given string with [Markdown syntax][markdown] and returns the associated HTML for that string.
Even though this code is confusingly written and hard to follow, somehow it works and all the tests are passing!
Your challenge is to re-write this code to make it easier to read and maintain while still making sure that all the tests keep passing.

It would be helpful if you made notes of what you did in your refactoring in comments so reviewers can see that, but it isn't strictly necessary.
The most important thing is to make the code better!

[markdown]: https://guides.github.com/features/mastering-markdown/
Loading

0 comments on commit 4978c6b

Please sign in to comment.