8000 04_removeFromArray: Add an additional solution using for loop, for ... of approach by VHadyak · Pull Request #291 · TheOdinProject/javascript-exercises · GitHub
[go: up one dir, main page]

Skip to content

04_removeFromArray: Add an additional solution using for loop, for ... of approach #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
55cfb17
Order exercise folders
remtaine Aug 7, 2021
61f38bf
Rename folders with numbers and underscores
remtaine Aug 7, 2021
3236ae1
Revert edits
remtaine Aug 7, 2021
4cdc0d8
Merge pull request #170 from remtaine/main
twalton83 Aug 7, 2021
79e57dd
Update README.md
davidnth Aug 8, 2021
702d983
Update README.md
davidnth Aug 8, 2021
7ec7672
Merge pull request #171 from davidnth/patch-1
twalton83 Aug 8, 2021
f045653
Add paragraph to repeatString describing arguments
msespos Aug 13, 2021
6274682
Merge two bullet points in repeatString
msespos Aug 13, 2021
137636a
Merge pull request #176 from msespos/edit-repeatstring-readme
twalton83 Aug 13, 2021
cb083f5
replaced semicolon with single quote in caesar
vishant-nambiar Aug 29, 2021
0c5601e
Merge pull request #181 from vishant-nambiar/fix/typo-in-caesar
twalton83 Sep 1, 2021
74ab0b7
add clarifiying comment about not removing code
I3uckwheat Sep 11, 2021
2197f7b
Merge pull request #183 from TheOdinProject/add-comments
I3uckwheat Sep 11, 2021
e4f9675
fix 'says hello world' in README.md
mohammedsobhi Sep 22, 2021
6b0e0e5
Merge pull request #186 from mohammedsobhi/patch-1
twalton83 Sep 22, 2021
36e36b5
Fixed a typo in line 41
yasledesma Nov 25, 2021
6527372
Remove predefined parameter from reverseString.js
chagstep1 Dec 27, 2021
09806f1
Fix typo
Jan 2, 2022
1004456
Merge pull request #210 from gerijeb/testFixing
CouchofTomato Jan 3, 2022
7a9377f
Update NPM instruction to new lesson link
programmurr Jan 18, 2022
b1a0bf9
Merge pull request #193 from HiddenOgre28/main
xandora Jan 27, 2022
efdfbd4
Merge pull request #206 from chagstep1/patch-1
xandora Jan 27, 2022
82db5ea
Merge pull request #215 from programmurr/.../...new-node-install
xandora Jan 27, 2022
1acdfcc
Fix palindromes false positive test
Mclilzee Feb 8, 2022
2f9f431
Merge pull request #227 from Mclilzee/main
xandora Feb 12, 2022
1b43007
Update README.md
thatblindgeye Feb 14, 2022
6dd594c
Create PULL_REQUEST_TEMPLATE.md
thatblindgeye Feb 14, 2022
baa5b0a
Create bug_report.md
thatblindgeye Feb 14, 2022
417ee0d
Create feature_request.md
thatblindgeye Feb 14, 2022
edb9c24
Remove irrelevant text about order of completion
jernestmyers Feb 14, 2022
2ebbb5a
Merge pull request #232 from jernestmyers/fix/update-readme
01zulfi Feb 16, 2022
2b54b1d
Merge branch 'main' into thatblindgeye-patch-1
thatblindgeye Feb 16, 2022
0760595
Update README.md
thatblindgeye Feb 16, 2022
67d4d0a
Update README.md
thatblindgeye Feb 17, 2022
1971712
Merge pull request #230 from TheOdinProject/thatblindgeye-patch-1
thatblindgeye Feb 17, 2022
f002e3d
Update feature_request.md
thatblindgeye Feb 20, 2022
f82c72f
Update bug_report.md
thatblindgeye Feb 20, 2022
649f0e3
Update PULL_REQUEST_TEMPLATE.md
thatblindgeye Feb 20, 2022
2586a84
Merge pull request #231 from TheOdinProject/thatblindgeye-patch-2
thatblindgeye Feb 22, 2022
0747078
Updated Installing Node JS lesson URL
KevinMulhern Mar 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: Bug Report
about: Create a report to help us improve something that is not working correctly
title: "Bug - :"
labels: "Status: Needs Review, Type: Bug"
assignees: ""
---

<!-- Thank you for taking the time to submit a bug report to The Odin Project. In order to get issues closed in a reasonable amount of time, you must include a baseline of information about the bug in question. Please read this template in its entirety before filling it out to ensure that it is filled out correctly. -->

Complete the following REQUIRED checkboxes:
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md)
- [ ] The title of this issue follows the `Bug - location of bug: brief description of bug` format, e.g. `Bug - Exercises: File type incorrect for all test files`

The following checkbox is OPTIONAL:
<!-- Completing this checkbox does not guarantee you will be assigned this issue, but rather lets us know you are interested in working on it. -->
- [ ] I would like to be assigned this issue to work on it

<hr>

**1. Description of the Bug:**
<!-- A clear and concise description of what the bug is. Include any screenshots that may help show the bug in action. -->


**2. How To Reproduce:**
<!--
What steps one might need to take in order to reproduce this bug, e.g.:
1. Log in
2. Visit a lesson page
3. Click the complete button
4. The complete button does not update
-->


**3. Expected Behavior:**
<!--
A brief description of what you expected to happen, e.g.:
1. Log in
2. Visit a lesson page
3. Click the complete button
4. The complete button updates correctly
-->


**4. Desktop/Device:**
<!-- The more information you are able to provide, the better. -->
- Device: <!-- [e.g. iPhone6] -->
- OS: <!-- [e.g. iOS] -->
- Browser: <!-- [e.g. chrome, safari] -->
- Version: <!-- [e.g. 22] -->

**5. Additional Information:**
<!-- Any additional information about the bug. -->

38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Feature Request
about: Suggest a new feature or enhancement for this project
title: ""
labels: "Status: Needs Review"
assignees: ""
---

<!-- Thank you for taking the time to submit a new feature request to The Odin Project. In order to get issues closed in a reasonable amount of time, you must include a baseline of information about the feature/enhancement you are proposing. Please read this template in its entirety before filling it out to ensure that it is filled out correctly. -->

Complete the following REQUIRED checkboxes:
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md)
- [ ] The title of this issue follows the `location for request: brief description of request` format, e.g. `Exercises: Add exercise on XYZ`

The following checkbox is OPTIONAL:
<!-- Completing this checkbox does not guarantee you will be assigned this issue, but rather lets us know you are interested in working on it. -->
- [ ] I would like to be assigned this issue to work on it

<hr>

**1. Description of the Feature Request:**
<!--
A clear and concise description of what the feature or enhancement is, including how it would be useful/beneficial or what problem(s) it would solve.
-->


**2. Acceptance Criteria:**
<!--
A list of checkbox items that explain the requirements needed to be met to resolve this request, e.g.:
- [ ] A theme toggle is present on the dashboard
- [ ] Clicking the theme toggle changes between light and dark
- [ ] A user's theme choice persists after leaving the website
-->


**3. Additional Information:**
<!-- Any additional information about the feature request, such as a link to a Discord discussion, screenshots, etc. -->

30 changes: 30 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Thank you for taking the time to contribute to The Odin Project. In order to get a pull request (PR) closed in a reasonable amount of time, you must include a baseline of information about the changes you are proposing. Please read this template in its entirety before filling it out to ensure that it is filled out correctly. -->

Complete the following REQUIRED checkboxes:
<!-- While editing this template, replace the whitespace between the square brackets with an 'x', e.g. [x] -->
- [ ] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md)
- [ ] The title of this PR follows the `location of change: brief description of change` format, e.g. `01_helloWorld: Update test cases`

Complete the following checkboxes ONLY IF they are applicable to your PR. You can complete them later if they are not currently applicable:
- [ ] I have ensured any exercise files included in this PR have passed all of their tests

<hr>

**1. Because:**
<!--
If this PR closes an open issue, replace the XXXXX below with the issue number, e.g. Closes #2013. Or if the issue is in another TOP repo replace the #XXXXX with the URL of the F438 issue, e.g. Closes https://github.com/TheOdinProject/curriculum/issues/XXXXX

Otherwise, provide a clear and concise reason for your pull request, e.g. what problem it solves or what benefit it provides. If this PR is related to, but does not close, another issue or PR, you can also link it as above without the 'Closes' keyword, e.g. "Related to #2013".
-->
Closes #XXXXX


**2. This PR:**
<!--
A bullet point list of one or more items outlining what was done in this PR to solve the problem(s) or implement the feature/enhancement.
-->


**3. Additional Information:**
<!-- Any additional information about the PR, such as a link to a Discord discussion, etc. -->

4 changes: 2 additions & 2 deletions helloWorld/README.md → 01_helloWorld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Let's look at the spec file first:
const helloWorld = require('./helloWorld');

describe('Hello World', function() {
test('says hello world', function() {
test('says "Hello, World!"', function() {
expect(helloWorld()).toEqual('Hello, World!');
});
});
Expand All @@ -38,7 +38,7 @@ Go ahead and see if you can make the test pass by editing the return value of th

Just to make sure, in case you're confused at this point, the test is telling you that running the function `helloWorld` should return the phrase `Hello, World!`. Punctuation and capitalization definitely matter here, so double check that if the test still isn't passing.

this is what the final function should look like:
This is what the final function should look like:
```javascript
const helloWorld = function() {
return 'Hello, World!'
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions repeatString/README.md → 02_repeatString/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Write a function that simply repeats the string a given number of times:
repeatString('hey', 3) // returns 'heyheyhey'
```

This function will take two arguments, `string` and `num`.

*Note:* The exercises after this one will not have arguments provided as this one does - you will need to provide them yourself from now on. So read each exercise's README carefully to see what kinds of arguments will be expected.

You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `.skip` from the `test.skip()` function.


Expand All @@ -17,11 +21,9 @@ You will notice in this exercise that there are multiple tests (see in file `rep

- Create a variable to hold the string you're going to return, create a loop that repeats the given number of times and add the given string to the result on each loop.

- If running `npm test repeatString.spec.js` returns results similar to the below:
- If running `npm test repeatString.spec.js` returns results similar to the below, make sure you have enabled the rest of the tests, as described in the instructions above.

```
Test Suites: 1 passed, 1 total
Tests: 6 skipped, 1 passed, 7 total
```

- Make sure you have enabled the rest of the tests (see above).
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const repeatString = function() {

};

// Do not edit below this line
module.exports = repeatString;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('repeatString', () => {
const number = Math.floor(Math.random() * 1000)
/*The .match(/((hey))/g).length is a regex that will count the number of heys
in the result, which if your function works correctly will equal the number that
was randomaly generated. */
was randomly generated. */
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
});
test.skip('works with blank strings', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const reverseString = function() {

};

// Do not edit below this line
module.exports = reverseString;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const removeFromArray = function() {

};

// Do not edit below this line
module.exports = removeFromArray;
File renamed without changes.
1 change: 1 addition & 0 deletions sumAll/sumAll.js → 05_sumAll/sumAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const sumAll = function() {

};

// Do not edit below this line
module.exports = sumAll;
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions 10000 leapYears/leapYears.js → 06_leapYears/leapYears.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const leapYears = function() {

};

// Do not edit below this line
module.exports = leapYears;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ctof = function() {

};

// Do not edit below this line
module.exports = {
ftoc,
ctof
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions calculator/calculator.js → 08_calculator/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const factorial = function() {

};

// Do not edit below this line
module.exports = {
add,
subtract,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const palindromes = function () {

};

// Do not edit below this line
module.exports = palindromes;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ describe('palindromes', () => {
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
});
test.skip('doesn\'t just always return true', () => {
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
expect(palindromes('ZZZZ car, a man, a maracaz.')).toBe(false);
});
});
File renamed without changes.
1 change: 1 addition & 0 deletions fibonacci/fibonacci.js → 10_fibonacci/fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const fibonacci = function() {

};

// Do not edit below this line
module.exports = fibonacci;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const getTheTitles = function() {

};

// Do not edit below this line
module.exports = getTheTitles;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const findTheOldest = function() {

};

// Do not edit below this line
module.exports = findTheOldest;
2 changes: 1 addition & 1 deletion caesar/README.md → 13_caesar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ caesar('A', 1) // simply shifts the letter by 1: returns 'B'

the cipher should retain capitalization:
```javascript
caesar('Hey', 5) // returns 'Mjd;
caesar('Hey', 5) // returns 'Mjd'
```

should _not_ shift punctuation:
Expand Down
1 change: 1 addition & 0 deletions caesar/caesar.js → 13_caesar/caesar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const caesar = function() {

};

// Do not edit below this line
module.exports = caesar;
File renamed without changes.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
10000 These are a series of JavaScript exercises intended to be used alongside the curriculum at 'The Odin Project'. They start simple and easy but get more complex and involved as you progress through them.
# JavaScript Exercises

There will eventually be a suggested order of completion, but at this time since we are still in the process of creating more exercises the order is subject to change and has not yet been specified. However, there are a few exercises that make a good "starting point". Feel free to at least start with these:
These JavaScript exercises are intended to complement the JavaScript content on The Odin Project (TOP). They should only be done when instructed during the course of the curriculum.

1. Hello World
2. Repeat String
3. Reverse String
**Note:** The `generator-exercise` file is not actually an exercise; it is a script that generates exercises. It was created to help efficiently write these exercises.

## Contributing

If you have a suggestion to improve an exercise, an idea for a new exercise, or notice an issue with an exercise, please feel free to open an issue after thoroughly reading our [contributing guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md) in our main TOP repo.

## How To Use These Exercises
Before you start you should have a few things installed on your machine:
1. **NPM**. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md).
2. **A copy of this repository**. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
3. **Jest**. After cloning this repository to your local machine, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings.

Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'test.skip' compared to 'test'. This is purposeful. After you pass your first 'test', you will change the next 'test.skip' to an 'test' and test your code again. You'll do this until all conditions are satisfied. **ALL TESTS MUST PASS AT THE SAME TIME.**
1. Fork and clone this repository. To learn how to fork a repository, see the GitHub documentation on how to [fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
* Copies of repositories on your machine are called clones. If you need help cloning to your local environment you can learn how from the GitHub documentation on [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository).
2. Before you start working on any execises, you should first ensure you have the following installed:
* **NPM**. You should have installed NPM already in our [Installing Node.js](https://www.theodinproject.com/lessons/foundations-installing-node-js) lesson. Just in case you need to check, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, **do not follow the instructions in the terminal** to install with `apt-get` as this causes permission issues. Instead, go back to the installation lesson and install Node with NVM by following the instructions there.
* **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings.
3. Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output.
* When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass.
4. Some of the exercises have test conditions defined in their spec file as `test.skip` compared to `test`. This is purposeful. After you pass one `test`, you will change the next `test.skip` to `test` and test your code again. You'll do this until all conditions are satisfied. **All tests must pass at the same time**, and you should not have any `test.skip` instances by the time you finish an exercise.
5. Once you successfully finish an exercise, check TOP's `solutions` branch to compare it with yours.
* You should not be checking the solution for an exercise until you finish it!
* Keep in mind that TOP's solution is not the only solution. Generally as long as all of the tests pass, your solution should be fine.
6. Do not submit your solutions to this repo, as any PRs that do so will be closed without merging.

**Note**: Due to the way Jest handles failed tests, it may return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.

The first exercise, `helloWorld`, will walk you through the process in-depth.

## Solutions

Solutions for these exercises can be found in this repo on the 'solutions' branch.

## A quick note!
## Debugging

The exercise `generator-exercise` is not actually an exercise; it is a script that generates exercises. It was created to help efficiently write these exercises.
To debug functions, you can run the tests in the Visual Studio Code debugger terminal. You can open this by clicking the "Run and Debug" icon on the left or pressing `ctrl + shift + D`, then clicking JavaScript Debug Terminal. You will be able to set breakpoints as you would in the Chrome DevTools debugger. You can run `npm test exerciseName.spec.js` to then execute your code up until your breakpoint and step through your code as necessary. **NOTE**: To take advantage of the debugger, you **MUST** run the script in the debugger terminal, not the bash or zsh terminal.
Binary file removed caesar/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion pigLatin/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ function pigLatin(string) {

};

module.exports = pigLatin;
// Do not edit below this line
module.exports = pigLatin;
1 change: 1 addition & 0 deletions snakeCase/snakeCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const snakeCase = function() {

};

// Do not edit below this line
module.exports = snakeCase;
0