Skip to content

Commit

Permalink
feat: Initial commit of new exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-hughes committed Oct 2, 2023
0 parents commit 8d8af99
Show file tree
Hide file tree
Showing 25 changed files with 12,410 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},

"env": {
"es6": true,
"jest": true,
"node": true
},
"rules": {
"no-loss-of-precision": "off",
"no-nonoctal-decimal-escape": "off",
"no-unsafe-optional-chaining": "off",
"no-useless-backreference": "off"
}
}
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
152 changes: 152 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# ✨ JavaScript Practice ✨

This repository contains 7 sets of exercises which will help you to build your ability and confidence with JavaScript. Completing all 8 sets would be ideal, but please ensure you complete at least the first 5.

We will be checking over your solutions, so please ensure you `commit` after solving each problem, and don't forget to `push` to GitHub regularly.

You may find these exercises challenging but they give you the opportunity to showcase your Growth Mindset and commitment to programming and learning. You can always come to us if you are having any trouble! 😊

If you need reminding of any key Javascript concepts to solve these challenges we recommend the 'Codecademy: Learn Javascript' (free) course: https://www.codecademy.com/learn/introduction-to-javascript

NOTE: You are not required to purchase any PRO content from codecademy.

We also recommend this visual guide if you are unfamiliar with GitHub: https://agripongit.vincenttunru.com/

Remember to break down problems to help you solve them and that Google is your friend!

### 🗺 Instructions

To complete these challenges you will need to have Node.js installed on your computer. Follow this link and click on the green button to install for Mac or Windows: https://nodejs.org/en/download/

👉 We recommend using the most recent LTS (Long-Term Support) version of Node, which is currently Node 18.

A download will start. When a pop-up appears please follow the installation instructions.

To check you have installed Node.js correctly, go to your terminal and type:

node --version

Your terminal should respond with the version of Node you have installed. It will look something similar to the following:

v18.16.0

🔍 Don't worry if you don't see the exact same version of Node 18.

Once you've got Node installed you can make a start - before you do please make sure to watch the [getting started video](https://storage.googleapis.com/your-return-to-tech/assessment-centre/assessment_exercises_guidance.mp4) as it walks you through instructions for getting started and the first exercise.

The short version is that you must:

👉 Use the Github website to `fork` the repository into your account.

👉 Use the `git clone` command _on the forked repository in your account_ to make a local copy of the repository on your computer.

👉 Install the dependencies in your local copy using `npm install`

👉 Complete the challenges.

👉 Use `git add`, `git commit` and `git push` to upload your work to the forked repository on your github account.

### 💻 Completing the challenges

👉 First, look inside the **docs** directory. Each exercise has an accompanying `md` file which contains instructions, hints and tips, so be sure to read these!

👉 Next, look inside the **challenges** directory.

📗 Each JavaScript file in the **challenges** has an accompanying explanation in the **docs** folder, which includes handy tips and information to expand your learning.

🕵️ The first few JavaScript files have a corresponding file in the **tests** folder. After that you have to write your own tests too! 🥳

Your task is to make every test pass for each file. To run the tests, use the command:

npm test

Work through each test one by one until you have them all passing. Initially, you'll have a lot of failing tests and a lot of output on the console. To focus on a single test, you can add `.only` to the test you are interested in:

```javascript
describe('capitalize', () => {
test.only('returns a capitalized word', () => {
expect(capitalize('hello')).toBe('Hello');
});

test('does nothing if the word is already capitalized', () => {
expect(capitalize('Hello')).toBe('Hello');
});

test('capitalizes the first word of a sentence', () => {
expect(capitalize('the quick fox')).toBe('The quick fox');
});
});
```

⚠️ Don't forget to remove `.only` afterwards so you can run all your tests again.

You can also ignore tests momentarily by adding an `x` at the front:

```javascript
xdescribe('capitalize', () => {
test('returns a capitalized word', () => {
expect(capitalize('hello')).toBe('Hello');
});

test('does nothing if the word is already capitalized', () => {
expect(capitalize('Hello')).toBe('Hello');
});

test('capitalizes the first word of a sentence', () => {
expect(capitalize('the quick fox')).toBe('The quick fox');
});
});
```

⚠️ But make sure when you push remotely to github that you have re-enabled all the tests!

Lastly, to run **ONE** test file at a time you can use the command `npm test` followed by the path to the file:

npm test test/exercise4.test.js

### 🔎 Edge cases

We have provided basic tests for each function - but can you think of any more tests which would help make sure these functions behave correctly? 🧐

Think about **edge cases**, which are use cases for your function which you might not ordinarily expect, but which you need to handle regardless.

For example, the first function should capitalize a string. So we have tested that it works for a single word:

`capitalize("hello") --> "Hello"`

What about a longer string:

`capitalize("hello world") --> "Hello world"`

And when the string is already capitalized:

`capitalize("Hello everyone") --> "Hello everyone"`

What if the string contains no characters?

`capitalize("") --> ""`

👉 Try adding extra tests to cover possibilities that the existing tests miss!

### 🧹 Linting

To help you write "clean", tidy code, we've included some rules for [Eslint](https://eslint.org/) in the `.eslintrc` file in this repository.

Eslint helps by spotting common errors such as undefined variables. This is hugely beneficial, as it alerts you to many errors before you even run your code! It also helps you write code that will be easy for you and other developers to read in the future.

It is configured with a set of standard rules, which can be viewed [here](https://eslint.org/docs/rules/).

For reporting as-you-type, install and enable the eslint extension for VSCode. To do this:

1. Click the square symbol on the left hand bar for extensions
2. Search for "eslint" and click install

Alternatively, you can manually run eslint by running this command in the root folder of this repository on your machine:

npx eslint ./

If there is no output then `eslint` has found no errors 🥳 If there are errors, you should fix them before committing your code.

# 🔥 The first challenge 🔥

Open [the first challenge instructions](docs/exercise1.md) to get started! 🙌
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
24 changes: 24 additions & 0 deletions challenges/exercise1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export function getFillings(sandwich) {
if (sandwich === undefined) throw new Error('ingredients is required');
// Your code here!
}

export function isFromManchester(person) {
if (person === undefined) throw new Error('person is required');
// Your code here!
}

export function getBusNumbers(people) {
if (people === undefined) throw new Error('people is required');
// Your code here!
}

export function countSheep(arr) {
if (arr === undefined) throw new Error('arr is required');
// Your code here!
}

export function hasMPostCode(person) {
if (person === undefined) throw new Error('person is required');
// Your code here!
}
26 changes: 26 additions & 0 deletions challenges/exercise2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function getSquares(nums) {
if (nums === undefined) throw new Error('nums is required');
// Your code here!
}

export function camelCaseWords(words) {
if (words === undefined) throw new Error('words is required');
// Your code here!
}

export function getTotalSubjects(people) {
if (people === undefined) throw new Error('people is required');
// Your code here!
}

export function checkIngredients(menu, ingredient) {
if (menu === undefined) throw new Error('menu is required');
if (!ingredient) throw new Error('ingredient is required');
// Your code here!
}

export function duplicateNumbers(arr1, arr2) {
if (arr1 === undefined) throw new Error('arr1 is required');
if (arr2 === undefined) throw new Error('arr2 is required');
// Your code here!
}
41 changes: 41 additions & 0 deletions challenges/exercise3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export function findSmallNums(nums) {
if (!nums) throw new Error('nums is required');
// Your code here
}

export function findNamesBeginningWith(names, char) {
if (!names) throw new Error('names is required');
if (!char) throw new Error('char is required');
// Your code here
}

export function findVerbs(words) {
if (!words) throw new Error('words is required');
// Your code here
}

export function getIntegers(nums) {
if (!nums) throw new Error('nums is required');
// Your code here
}

export function getCities(users) {
if (!users) throw new Error('users is required');
// Your code here
}

export function getSquareRoots(nums) {
if (!nums) throw new Error('nums is required');
// Your code here
}

export function findSentencesContaining(sentences, str) {
if (!sentences) throw new Error('sentences is required');
if (!str) throw new Error('str is required');
// Your code here
}

export function getLongestSides(triangles) {
if (!triangles) throw new Error('triangles is required');
// Your code here
}
36 changes: 36 additions & 0 deletions challenges/exercise4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const findNextNumber = (nums, n) => {
if (nums === undefined) throw new Error('nums is required');
if (n === undefined) throw new Error('n is required');
// Your code here!
};

export const count1sand0s = (str) => {
if (str === undefined) throw new Error('str is required');
// Your code here!
};

export const reverseNumber = (n) => {
if (n === undefined) throw new Error('n is required');
// Your code here!
};

export const sumArrays = (arrs) => {
if (arrs === undefined) throw new Error('arrs is required');
// Your code here!
};

export const arrShift = (arr) => {
if (arr === undefined) throw new Error('arr is required');
// Your code here!
};

export const findNeedle = (haystack, searchTerm) => {
if (haystack === undefined) throw new Error('haystack is required');
if (searchTerm === undefined) throw new Error('searchTerm is required');
// Your code here!
};

export const getWordFrequencies = (str) => {
if (str === undefined) throw new Error('str is required');
// Your code here!
};
Loading

0 comments on commit 8d8af99

Please sign in to comment.