-
-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
1,240 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ises/practice/pop-count/pop-count.spec.js → .../practice/eliuds-eggs/eliuds-eggs.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
Oops, something went wrong.