Merge pull request #45 from Bouncey/fix/ui

Fix up the UI and pull in the latest seed files
This commit is contained in:
Stuart Taylor
2018-05-18 14:54:21 +01:00
committed by Mrugesh Mohapatra
parent 04a6a2026c
commit f962d7774a
105 changed files with 7019 additions and 9431 deletions

View File

@@ -6,7 +6,7 @@
"challenges": [
{
"id": "a3f503de51cf954ede28891d",
"title": "Symmetric Difference",
"title": "Find the Symmetric Difference",
"description": [
"Create a function that takes two or more arrays and returns an array of the <dfn>symmetric difference</dfn> (<code>&xutri;</code> or <code>&oplus;</code>) of the provided arrays.",
"Given two sets (for example set <code>A = {1, 2, 3}</code> and set <code>B = {2, 3, 4}</code>), the mathematical term \"symmetric difference\" of two sets is the set of elements which are in either of the two sets, but not in both (<code>A &xutri; B = C = {1, 4}</code>). For every additional symmetric difference you take (say on a set <code>D = {2, 3}</code>), you should get the set with elements which are in either of the two the sets but not both (<code>C &xutri; D = {1, 4} &xutri; {2, 3} = {1, 2, 3, 4}</code>). The resulting array must contain only unique values (<em>no duplicates</em>).",
@@ -117,8 +117,8 @@
"",
"sym([1, 2, 3], [5, 2, 1, 4]);"
],
"head": "",
"tail": ""
"head": [],
"tail": []
}
}
},
@@ -214,8 +214,8 @@
"",
"updateInventory(curInv, newInv);"
],
"head": "",
"tail": ""
"head": [],
"tail": []
}
}
},
@@ -316,8 +316,8 @@
"",
"permAlone('aab');"
],
"head": "",
"tail": ""
"head": [],
"tail": []
}
}
},
@@ -326,7 +326,7 @@
"title": "Pairwise",
"description": [
"Given an array <code>arr</code>, find element pairs whose sum equal the second argument <code>arg</code> and return the sum of their indices.",
"You may use multiple pairs that have the same numeric elements but different indices. Each pair should use the lowest possible available indices. Once an element has been used it cannot be reused to pair with another element.",
"You may use multiple pairs that have the same numeric elements but different indices. Each pair should use the lowest possible available indices. Once an element has been used it cannot be reused to pair with another element. For instance, <code>pairwise([1, 1, 2], 3)</code> creates a pair <code>[2, 1]</code> using the 1 at indice 0 rather than the 1 at indice 1, because 0+2 < 1+2.",
"For example <code>pairwise([7, 9, 11, 13, 15], 20)</code> returns <code>6</code>. The pairs that sum to 20 are <code>[7, 13]</code> and <code>[9, 11]</code>. We can then write out the array with their indices and values.",
"<table class=\"table\"><tr><th><strong>Index</strong></th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th></tr><tr><td>Value</td><td>7</td><td>9</td><td>11</td><td>13</td><td>15</td></tr></table>",
"Below we'll take their corresponding indices and add them.",
@@ -410,8 +410,8 @@
"",
"pairwise([1,4,2,3,0,5], 7);"
],
"head": "",
"tail": ""
"head": [],
"tail": []
}
}
},
@@ -423,7 +423,7 @@
"Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and 'bubbles up' unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.",
"This method requires multiple iterations through the array and for average and worst cases has quadratic time complexity. While simple, it is usually impractical in most situations.",
"<strong>Instructions:</strong> Write a function <code>bubbleSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.",
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting alogrithm in action!"
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!"
],
"tests": [
{
@@ -464,8 +464,13 @@
"// test array:",
"// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]"
],
"head": "",
"tail": "function isSorted(arr) {\n var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);\n return check(0);\n};"
"head": [],
"tail": [
"function isSorted(arr) {",
" var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);",
" return check(0);",
"};"
]
}
}
},
@@ -474,8 +479,8 @@
"title": "Implement Selection Sort",
"description": [
"Here we will implement selection sort. Selection sort works by selecting the minimum value in a list and swapping it with the first value in the list. It then starts at the second position, selects the smallest value in the remaining list, and swaps it with the second element. It continues iterating through the list and swapping elements until it reaches the end of the list. Now the list is sorted. Selection sort has quadratic time complexity in all cases.",
"<stong>Instructions</stong>: Write a function <code>selectionSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.",
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting alogrithm in action!"
"<strong>Instructions</strong>: Write a function <code>selectionSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.",
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!"
],
"tests": [
{
@@ -516,8 +521,13 @@
"// test array:",
"// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]"
],
"head": "",
"tail": "function isSorted(arr) {\n var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);\n return check(0);\n};"
"head": [],
"tail": [
"function isSorted(arr) {",
" var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);",
" return check(0);",
"};"
]
}
}
},
@@ -527,7 +537,7 @@
"description": [
"The next sorting method we'll look at is insertion sort. This method works by building up a sorted array at the beginning of the list. It begins the sorted array with the first element. Then it inspects the next element and swaps it backwards into the sorted array until it is in sorted position. It continues iterating through the list and swapping new items backwards into the sorted portion until it reaches the end. This algorithm has quadratic time complexity in the average and worst cases.",
"<strong>Instructions:</strong> Write a function <code>insertionSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.",
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting alogrithm in action!"
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!"
],
"tests": [
{
@@ -568,8 +578,13 @@
"// test array:",
"// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]"
],
"head": "",
"tail": "function isSorted(arr) {\n var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);\n return check(0);\n};"
"head": [],
"tail": [
"function isSorted(arr) {",
" var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);",
" return check(0);",
"};"
]
}
}
},
@@ -580,7 +595,7 @@
"Here we will move on to an intermediate sorting algorithm: quick sort. Quick sort is an efficient, recursive divide-and-conquer approach to sorting an array. In this method, a pivot value is chosen in the original array. The array is then partitioned into two subarrays of values less than and greater than the pivot value. We then combine the result of recursively calling the quick sort algorithm on both sub-arrays. This continues until the base case of an empty or single-item array is reached, which we return. The unwinding of the recursive calls return us the sorted array.",
"Quick sort is a very efficient sorting method, providing <i>O(nlog(n))</i> performance on average. It is also relatively easy to implement. These attributes make it a popular and useful sorting method.",
"<strong>Instructions:</strong> Write a function <code>quickSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. While the choice of the pivot value is important, any pivot will do for our purposes here. For simplicity, the first or last element could be used.",
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting alogrithm in action!"
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!"
],
"tests": [
{
@@ -621,8 +636,13 @@
"// test array:",
"// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]"
],
"head": "",
"tail": "function isSorted(arr) {\n var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);\n return check(0);\n};"
"head": [],
"tail": [
"function isSorted(arr) {",
" var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);",
" return check(0);",
"};"
]
}
}
},
@@ -636,7 +656,7 @@
"Merge sort is an efficient sorting method, with time complexity of <i>O(nlog(n))</i>. This algorithm is popular because it is performant and relatively easy to implement.",
"As an aside, this will be the last sorting algorithm we cover here. However, later in the section on tree data structures we will describe heap sort, another efficient sorting method that requires a binary heap in its implementation.",
"<strong>Instructions:</strong> Write a function <code>mergeSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. A good way to implement this is to write one function, for instance <code>merge</code>, which is responsible for merging two sorted arrays, and another function, for instance <code>mergeSort</code>, which is responsible for the recursion that produces single-item arrays to feed into merge. Good luck!",
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting alogrithm in action!"
"<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!"
],
"tests": [
{
@@ -677,13 +697,15 @@
"// test array:",
"// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]"
],
"head": "",
"tail": "function isSorted(arr) {\n var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);\n return check(0);\n};"
"head": [],
"tail": [
"function isSorted(arr) {",
" var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);",
" return check(0);",
"};"
]
}
}
}
],
"fileName": "08-coding-interview-questions-and-take-home-assignments/coding-interview-algorithm-questions.json",
"superBlock": "coding-interview-questions-and-take-home-assignments",
"superOrder": 8
]
}

View File

@@ -0,0 +1,249 @@
# A guide to improve Project Euler's problems
Thank you for contributing to freeCodeCamp, your help is definitely needed here!
freeCodeCamp is having a great breakthrough ahead, one of it is to prepare
campers for interview questions, and Project Euler is one of them.
And to let campers having fun with this challenges during Christmas, we are
going to have a lot of help here to improve the challenges of Project Euler
problems (so people won't cheating by returning the value right away, since
Project Euler's problems only assert one answer.)
**Table of Contents**
* [What is Project Euler](#what-is-project-euler)
* [How to improve the problems](#how-to-improve-the-problems)
## What is Project Euler
[Project Euler](https://projecteuler.net/) is a series of challenging
mathematical/computer programming problems that will require more than just
mathematical insights to solve. Although mathematics will help you arrive at
elegant and efficient methods, the use of a computer and programming skills will
be required to solve most problems.
The motivation for starting Project Euler, and its continuation, is to provide a
platform for the inquiring mind to delve into unfamiliar areas and learn new
concepts in a fun and recreational context.
## How to improve the problems
The Project Euler problems seed can be found at
`seed/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json`
Here's what it will look like (this is before the improvements, take problem 23
as the example)
```javascript
{
"_id": "5900f3831000cf542c50fe96",
"challengeType": 5,
"type": "bonfire",
"title": "Problem 23: Non-abundant sums",
"tests": [
"assert.strictEqual(euler23(), 4179871, 'message: <code>euler23()</code> should return 4179871.');"
],
"solutions": [],
"translations": {},
"challengeSeed": [
"function euler23() {",
" // Good luck!",
" return true;",
"}",
"",
"euler23();"
],
"description": [
"A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.",
"A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.",
"",
"As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.",
"Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers."
]
},
```
and here's after some improvements
```javascript
{
"_id": "5900f3831000cf542c50fe96",
"challengeType": 5,
"type": "bonfire",
"title": "Problem 23: Non-abundant sums",
"tests": [
"assert(sumOfNonAbundantNumbers(10000) === 3731004, 'message: <code>sumOfNonAbundantNumbers(10000)</code> should return 3731004.');",
"assert(sumOfNonAbundantNumbers(15000) === 4039939, 'message: <code>sumOfNonAbundantNumbers(15000)</code> should return 4039939.');",
"assert(sumOfNonAbundantNumbers(20000) === 4159710, 'message: <code>sumOfNonAbundantNumbers(20000)</code> should return 4159710.');",
"assert(sumOfNonAbundantNumbers(28123) === 4179871, 'message: <code>sumOfNonAbundantNumbers(28123)</code> should return 4179871.');"
],
"solutions": [],
"translations": {},
"challengeSeed": [
"function sumOfNonAbundantNumbers(n) {",
" // Good luck!",
" return n;",
"}",
"",
"sumOfNonAbundantNumbers(28123);"
],
"description": [
"A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.",
"A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.",
"",
"As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.",
"Find the sum of all positive integers <= n which cannot be written as the sum of two abundant numbers."
]
},
```
Don't be confused now, here's what to do to improve the problems:
(We expect you already have forked freeCodeCamp's repository)
### Step 1: Create new branch at your git origin (e.g: `feature/problem_euler23`)
Always create the branch with the base refer to the newest freeCodeCamp's
staging branch, here's how to do that:
1. Do fetch staging branch from freeCodeCamp's repository `$ git fetch upstream
staging`
2. Checkout to the staging branch `$ git checkout upstream/staging`
3. Create branch from upstream/staging `$ git checkout -b <branch_name>`
### Step 2: Change the name of the function to more readable
For example, from `euler23()` into `sumOfNonAbundantNumbers()` We took the name
from the problem name :D
### Step 3: Solve the problem by yourself
Try to solve the problem by yourself but if you get stucked,
Here's what to do: you can go to [mathblog](http://www.mathblog.dk/) or
[dreamshire](https://blog.dreamshire.com) to find other people's solution
written in other languages (usually C and C#) Learn from their solution and port
it to JavaScript :) ( Always have the perspective of learning, don't just copy
paste other people's code )
So from the example here's my solution (We didn't include it in the JSON because
up till now, we couldn't find a way to fit it in, when we transformed it into
array of strings it spits out error when running `$ npm run test-challenges` it
will be awesome if you can find how to fits that right in)
```javascript
function sumOfNonAbundantNumbers() {
const getFactors = number => {
let factors = [];
let possibleFactor = 1;
let sqrt = Math.sqrt(number);
while (possibleFactor <= sqrt) {
if (number % possibleFactor == 0) {
factors[factors.length] = possibleFactor;
let otherPossibleFactor = number / possibleFactor;
if (otherPossibleFactor > possibleFactor)
factors[factors.length] = otherPossibleFactor;
}
possibleFactor++;
}
return factors;
};
const getAbundantNumbers = upperLimit => {
let abundantNumbers = [];
for (let i = 12; i <= upperLimit; i++) {
let factors = getFactors(i);
let factorSum = 0;
for (let factor, j = 0; (factor = factors[j]); j++)
if (i != factor) factorSum += factor;
if (factorSum > i) {
abundantNumbers.push(i);
}
}
return abundantNumbers;
};
var abundantNumbers = getAbundantNumbers(28123);
var sum = 0;
for (var testNum = 1; testNum <= 28123; testNum++) {
var sumOfAbundant = false;
for (
var i = 0, j = abundantNumbers.length - 1, abundantNumber1;
(abundantNumber1 = abundantNumbers[i]);
i++
) {
if (abundantNumber1 > testNum) {
break;
}
var abundantNumber2 = abundantNumbers[j];
while (j > 0 && abundantNumber1 + abundantNumber2 > testNum) {
abundantNumber2 = abundantNumbers[--j];
}
if (abundantNumber1 + abundantNumber2 == testNum) {
sumOfAbundant = true;
break;
}
}
if (!sumOfAbundant) {
sum += testNum;
}
}
return sum;
}
```
After finished solving the problem, you can improve the task a little bit, for
example compared to asking campers to find the sum of all the positive integers,
you can ask campers to find the sum of all positive integers <= n.
(if you add more assertions to the problem, always assert less than the original
problem, to prevent infinite loop, etc)
One last thing, always make sure that the return value of the function is always
the same data type to which you want the function to return
Like in the example above, we want the user to return integer, so we changed the
return value from true into integer.
### Step 4: Running Test on Arcade Mode
After done with the solution, run the test on
[ FCC's Arcade Mode ](https://github.com/freeCodeCamp/arcade-mode)
### Step 5: Commit changes and push to your origin
1. Do changes and add changed files to stage `$ git add .`
2. Commit those changes using `$ npm run commit` and follow the instruction
there.
3. And run `$ git push origin <branch_name>`
### Step 5: Create Pull Request to freeCodeCamp's staging branch
Create PR to freeCodeCamp's staging branch and wait for your code to be assesed
from the maintainer.
That's all it! if there's something unclear and you still have questions, you
can chat from gitter in
[Arcade-Mode](https://gitter.im/FreeCodeCamp/arcade-mode)
[Contributors](https://gitter.im/FreeCodeCamp/Contributors) or you can text me
right away @alvinkl
# Why do we have to improve Project Euler problems?
Our goal is to prevent user from cheating and just returning the project euler
result rightaway, and by giving more assertions and improving a bit of the task
we are able to make the challenge more challenging as well.
With your help, we can help people to practice their skills and be confident to
face technical interviews like this :)

File diff suppressed because one or more lines are too long