fix(curriculum): Consolidated comments for JavaScript Algorithms and Data Structures challenges - part 1 of 4 (#38258)

* fix: consolidate/remove comments

* fix: remove => from comment

* fix: reverted changes to add same changes to another PR

* fix: removed 'the' from sentence

Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* fix: removed 'the' from the sentence

Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Tom
2020-03-04 13:08:54 -06:00
committed by GitHub
parent 5294936667
commit 17a55c6e18
74 changed files with 123 additions and 237 deletions

View File

@ -54,7 +54,6 @@ tests:
```js ```js
function booWho(bool) { function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.
return bool; return bool;
} }

View File

@ -47,7 +47,6 @@ tests:
```js ```js
function chunkArrayInGroups(arr, size) { function chunkArrayInGroups(arr, size) {
// Break it up.
return arr; return arr;
} }

View File

@ -56,8 +56,6 @@ tests:
```js ```js
function confirmEnding(str, target) { function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str; return str;
} }

View File

@ -42,7 +42,6 @@ tests:
```js ```js
function bouncer(arr) { function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr; return arr;
} }

View File

@ -49,7 +49,6 @@ tests:
```js ```js
function repeatStringNumTimes(str, num) { function repeatStringNumTimes(str, num) {
// repeat after me
return str; return str;
} }

View File

@ -42,7 +42,6 @@ tests:
```js ```js
function largestOfFour(arr) { function largestOfFour(arr) {
// You can do this!
return arr; return arr;
} }

View File

@ -49,7 +49,6 @@ tests:
```js ```js
function frankenSplice(arr1, arr2, n) { function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
return arr2; return arr2;
} }

View File

@ -45,7 +45,6 @@ tests:
```js ```js
function truncateString(str, num) { function truncateString(str, num) {
// Clear out that junk in your trunk
return str; return str;
} }

View File

@ -67,7 +67,6 @@ tests:
```js ```js
function getIndexToIns(arr, num) { function getIndexToIns(arr, num) {
// Find my place in this sorted array.
return num; return num;
} }

View File

@ -61,13 +61,12 @@ tests:
```js ```js
function filteredArray(arr, elem) { function filteredArray(arr, elem) {
let newArr = []; let newArr = [];
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
return newArr; return newArr;
} }
// change code here to test different cases:
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)); console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
``` ```
@ -83,13 +82,11 @@ console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
```js ```js
function filteredArray(arr, elem) { function filteredArray(arr, elem) {
let newArr = []; let newArr = [];
// change code below this line
for (let i = 0; i<arr.length; i++) { for (let i = 0; i<arr.length; i++) {
if (arr[i].indexOf(elem) < 0) { if (arr[i].indexOf(elem) < 0) {
newArr.push(arr[i]); newArr.push(arr[i]);
} }
} }
// change code above this line
return newArr; return newArr;
} }
``` ```

View File

@ -72,9 +72,9 @@ tests:
```js ```js
function countOnline(usersObj) { function countOnline(usersObj) {
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
} }
``` ```

View File

@ -58,9 +58,9 @@ let user = {
}; };
function addFriend(userObj, friend) { function addFriend(userObj, friend) {
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
} }
console.log(addFriend(user, 'Pete')); console.log(addFriend(user, 'Pete'));

View File

@ -65,9 +65,9 @@ let userActivity = {
} }
}; };
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
console.log(userActivity); console.log(userActivity);
``` ```

View File

@ -51,9 +51,9 @@ let foods = {
strawberries: 27 strawberries: 27
}; };
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
console.log(foods); console.log(foods);
``` ```

View File

@ -79,8 +79,8 @@ var testObj = {
// Only change code below this line // Only change code below this line
var playerNumber; // Change this Line var playerNumber; // Change this line
var player = testObj; // Change this Line var player = testObj; // Change this line
``` ```
</div> </div>

View File

@ -75,7 +75,6 @@ function switchOfStuff(val) {
return answer; return answer;
} }
// Change this value to test
switchOfStuff(1); switchOfStuff(1);
``` ```

View File

@ -81,7 +81,6 @@ function testSize(num) {
// Only change code above this line // Only change code above this line
} }
// Change this value to test
testSize(7); testSize(7);
``` ```

View File

@ -69,7 +69,6 @@ function testEqual(val) {
return "Not Equal"; return "Not Equal";
} }
// Change this value to test
testEqual(10); testEqual(10);
``` ```

View File

@ -70,7 +70,6 @@ function testGreaterOrEqual(val) {
return "Less than 10"; return "Less than 10";
} }
// Change this value to test
testGreaterOrEqual(10); testGreaterOrEqual(10);
``` ```

View File

@ -62,7 +62,6 @@ function testNotEqual(val) {
return "Equal"; return "Equal";
} }
// Change this value to test
testNotEqual(10); testNotEqual(10);
``` ```

View File

@ -68,7 +68,6 @@ function testLessThan(val) {
return "55 or Over"; return "55 or Over";
} }
// Change this value to test
testLessThan(10); testLessThan(10);
``` ```

View File

@ -70,7 +70,6 @@ function testLessOrEqual(val) {
return "More Than 24"; return "More Than 24";
} }
// Change this value to test
testLessOrEqual(10); testLessOrEqual(10);
``` ```

View File

@ -57,7 +57,6 @@ function testStrict(val) {
return "Not Equal"; return "Not Equal";
} }
// Change this value to test
testStrict(10); testStrict(10);
``` ```

View File

@ -58,7 +58,6 @@ function testStrictNotEqual(val) {
return "Equal"; return "Equal";
} }
// Change this value to test
testStrictNotEqual(10); testStrictNotEqual(10);
``` ```

View File

@ -85,7 +85,6 @@ function testLogicalAnd(val) {
return "No"; return "No";
} }
// Change this value to test
testLogicalAnd(10); testLogicalAnd(10);
``` ```

View File

@ -89,7 +89,6 @@ function testLogicalOr(val) {
return "Inside"; return "Inside";
} }
// Change this value to test
testLogicalOr(15); testLogicalOr(15);
``` ```

View File

@ -61,8 +61,6 @@ function cc(card) {
// Only change code above this line // Only change code above this line
} }
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A'); cc(2); cc(3); cc(7); cc('K'); cc('A');
``` ```

View File

@ -59,7 +59,6 @@ function randomRange(myMin, myMax) {
} }
// Change these values to test your function
var myRandom = randomRange(5, 15); var myRandom = randomRange(5, 15);
``` ```

View File

@ -66,7 +66,6 @@ function golfScore(par, strokes) {
// Only change code above this line // Only change code above this line
} }
// Change these values to test
golfScore(5, 4); golfScore(5, 4);
``` ```

View File

@ -71,7 +71,6 @@ function testElseIf(val) {
return "Between 5 and 10"; return "Between 5 and 10";
} }
// Change this value to test
testElseIf(7); testElseIf(7);
``` ```

View File

@ -71,7 +71,6 @@ function testElse(val) {
return result; return result;
} }
// Change this value to test
testElse(4); testElse(4);
``` ```

View File

@ -85,7 +85,6 @@ function orderMyLogic(val) {
} }
} }
// Change this value to test
orderMyLogic(7); orderMyLogic(7);
``` ```

View File

@ -99,7 +99,7 @@ var myMusic = [
], ],
"gold": true "gold": true
} }
// Add record here // Add a record here
]; ];
``` ```

View File

@ -79,7 +79,6 @@ function sequentialSizes(val) {
return answer; return answer;
} }
// Change this value to test
sequentialSizes(1); sequentialSizes(1);
``` ```

View File

@ -61,7 +61,6 @@ function compareEquality(a, b) {
return "Not Equal"; return "Not Equal";
} }
// Change this value to test
compareEquality(10, "10"); compareEquality(10, "10");
``` ```

View File

@ -84,7 +84,6 @@ function lookUpProfile(name, prop){
// Only change code above this line // Only change code above this line
} }
// Change these values to test your function
lookUpProfile("Akira", "likes"); lookUpProfile("Akira", "likes");
``` ```

View File

@ -91,9 +91,7 @@ function updateRecords(id, prop, value) {
return collection; return collection;
} }
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA"); updateRecords(5439, "artist", "ABBA");
``` ```
</div> </div>

View File

@ -98,7 +98,6 @@ function chainToSwitch(val) {
return answer; return answer;
} }
// Change this value to test
chainToSwitch(7); chainToSwitch(7);
``` ```

View File

@ -68,7 +68,6 @@ function isLess(a, b) {
// Only change code above this line // Only change code above this line
} }
// Change these values to test
isLess(10, 15); isLess(10, 15);
``` ```

View File

@ -68,7 +68,6 @@ function caseInSwitch(val) {
return answer; return answer;
} }
// Change this value to test
caseInSwitch(1); caseInSwitch(1);
``` ```

View File

@ -78,7 +78,6 @@ function trueOrFalse(wasThatTrue) {
} }
// Change this value to test
trueOrFalse(true); trueOrFalse(true);
``` ```

View File

@ -99,7 +99,6 @@ function phoneticLookup(val) {
return result; return result;
} }
// Change this value to test
phoneticLookup("charlie"); phoneticLookup("charlie");
``` ```

View File

@ -43,9 +43,9 @@ tests:
```html ```html
<html> <html>
<body> <body>
<!-- add your code below --> <!-- Only change code below this line -->
<!-- add your code above --> <!-- Only change code above this line -->
</body> </body>
</html> </html>
``` ```
@ -59,9 +59,7 @@ tests:
```html ```html
<html> <html>
<body> <body>
<!-- add your code below -->
<script type="module" src="index.js"></script> <script type="module" src="index.js"></script>
<!-- add your code above -->
</body> </body>
</html> </html>
``` ```

View File

@ -37,7 +37,16 @@ This new way of creating strings gives you more flexibility to create robust str
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
Use template literal syntax with backticks to display each entry of the <code>result</code> object's <code>failure</code> array. Each entry should be wrapped inside an <code>li</code> element with the class attribute <code>text-warning</code>, and listed within the <code>resultDisplayArray</code>. Use template literal syntax with backticks to display each entry of the <code>result</code> object's <code>failure</code> array. Each entry should be wrapped inside an <code>li</code> element with the class attribute <code>text-warning</code>, and listed within the <code>resultDisplayArray</code>.
Use an iterator method (any kind of loop) to get the desired output. Use an iterator method (any kind of loop) to get the desired output (shown below).
```js
[
'<li class="text-warning">no-var</li>',
'<li class="text-warning">var-on-top</li>',
'<li class="text-warning">linebreak</li>'
]
```
</section> </section>
## Tests ## Tests
@ -71,18 +80,13 @@ const result = {
function makeList(arr) { function makeList(arr) {
"use strict"; "use strict";
// change code below this line // Only change code below this line
const resultDisplayArray = null; const resultDisplayArray = null;
// change code above this line // Only change code above this line
return resultDisplayArray; return resultDisplayArray;
} }
/**
* makeList(result.failure) should return:
* [ `<li class="text-warning">no-var</li>`,
* `<li class="text-warning">var-on-top</li>`,
* `<li class="text-warning">linebreak</li>` ]
**/
const resultDisplayArray = makeList(result.failure); const resultDisplayArray = makeList(result.failure);
``` ```
@ -108,12 +112,7 @@ function makeList(arr) {
return resultDisplayArray; return resultDisplayArray;
} }
/**
* makeList(result.failure) should return:
* [ `<li class="text-warning">no-var</li>`,
* `<li class="text-warning">var-on-top</li>`,
* `<li class="text-warning">linebreak</li>` ]
**/
const resultDisplayArray = makeList(result.failure); const resultDisplayArray = makeList(result.failure);
``` ```

View File

@ -53,14 +53,14 @@ tests:
function printManyTimes(str) { function printManyTimes(str) {
"use strict"; "use strict";
// change code below this line // Only change code below this line
var sentence = str + " is cool!"; var sentence = str + " is cool!";
for (var i = 0; i < str.length; i+=2) { for (var i = 0; i < str.length; i+=2) {
console.log(sentence); console.log(sentence);
} }
// change code above this line // Only change code above this line
} }
printManyTimes("freeCodeCamp"); printManyTimes("freeCodeCamp");
@ -79,15 +79,11 @@ printManyTimes("freeCodeCamp");
function printManyTimes(str) { function printManyTimes(str) {
"use strict"; "use strict";
// change code below this line
const SENTENCE = str + " is cool!"; const SENTENCE = str + " is cool!";
for (let i = 0; i < str.length; i+=2) { for (let i = 0; i < str.length; i+=2) {
console.log(SENTENCE); console.log(SENTENCE);
} }
// change code above this line
} }
printManyTimes("freeCodeCamp"); printManyTimes("freeCodeCamp");
``` ```

View File

@ -54,11 +54,11 @@ tests:
const s = [5, 7, 2]; const s = [5, 7, 2];
function editInPlace() { function editInPlace() {
'use strict'; 'use strict';
// change code below this line // Only change code below this line
// s = [2, 5, 7]; <- this is invalid // s = [2, 5, 7]; <- this is invalid
// change code above this line // Only change code above this line
} }
editInPlace(); editInPlace();
``` ```
@ -76,13 +76,9 @@ editInPlace();
const s = [5, 7, 2]; const s = [5, 7, 2];
function editInPlace() { function editInPlace() {
'use strict'; 'use strict';
// change code below this line
// s = [2, 5, 7]; <- this is invalid
s[0] = 2; s[0] = 2;
s[1] = 5; s[1] = 5;
s[2] = 7; s[2] = 7;
// change code above this line
} }
editInPlace(); editInPlace();
``` ```

View File

@ -58,10 +58,10 @@ function freezeObj() {
const MATH_CONSTANTS = { const MATH_CONSTANTS = {
PI: 3.14 PI: 3.14
}; };
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
try { try {
MATH_CONSTANTS.PI = 99; MATH_CONSTANTS.PI = 99;
} catch(ex) { } catch(ex) {
@ -87,10 +87,8 @@ function freezeObj() {
const MATH_CONSTANTS = { const MATH_CONSTANTS = {
PI: 3.14 PI: 3.14
}; };
// change code below this line
Object.freeze(MATH_CONSTANTS); Object.freeze(MATH_CONSTANTS);
// change code above this line
try { try {
MATH_CONSTANTS.PI = 99; MATH_CONSTANTS.PI = 99;
} catch(ex) { } catch(ex) {

View File

@ -65,12 +65,12 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
/* Alter code below this line */ // Only change code below this line
/* Alter code above this line */ // Only change code above this line
const carrot = new Vegetable('carrot'); const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot' console.log(carrot.name); // Should display 'carrot'
``` ```
</div> </div>

View File

@ -54,9 +54,9 @@ tests:
```js ```js
let a = 8, b = 6; let a = 8, b = 6;
// change code below this line // Only change code below this line
// change code above this line // Only change code above this line
console.log(a); // should be 6 console.log(a); // should be 6
console.log(b); // should be 8 console.log(b); // should be 8
``` ```

View File

@ -65,12 +65,12 @@ const LOCAL_FORECAST = {
tomorrow: { low: 68, high: 80 } tomorrow: { low: 68, high: 80 }
}; };
// change code below this line // Only change code below this line
const lowToday = LOCAL_FORECAST.today.low; const lowToday = LOCAL_FORECAST.today.low;
const highToday = LOCAL_FORECAST.today.high; const highToday = LOCAL_FORECAST.today.high;
// change code above this line // Only change code above this line
console.log(lowToday); // should be 64 console.log(lowToday); // should be 64
console.log(highToday); // should be 77 console.log(highToday); // should be 77
@ -89,12 +89,8 @@ const LOCAL_FORECAST = {
tomorrow: { low: 68, high: 80 } tomorrow: { low: 68, high: 80 }
}; };
// change code below this line
const { today: { low: lowToday, high: highToday }} = LOCAL_FORECAST; const { today: { low: lowToday, high: highToday }} = LOCAL_FORECAST;
// change code above this line
console.log(highToday); // should be 77 console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80 console.log(highTomorrow); // should be 80
``` ```

View File

@ -56,12 +56,12 @@ const HIGH_TEMPERATURES = {
tomorrow: 80 tomorrow: 80
}; };
// change code below this line // Only change code below this line
const highToday = HIGH_TEMPERATURES.today; const highToday = HIGH_TEMPERATURES.today;
const highTomorrow = HIGH_TEMPERATURES.tomorrow; const highTomorrow = HIGH_TEMPERATURES.tomorrow;
// change code above this line // Only change code above this line
console.log(yesterday) // should be not defined console.log(yesterday) // should be not defined
console.log(highToday); // should be 77 console.log(highToday); // should be 77
@ -81,12 +81,8 @@ const HIGH_TEMPERATURES = {
tomorrow: 80 tomorrow: 80
}; };
// change code below this line
const { today: highToday, tomorrow: highTomorrow } = HIGH_TEMPERATURES; const { today: highToday, tomorrow: highTomorrow } = HIGH_TEMPERATURES;
// change code above this line
console.log(highToday); // should be 77 console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80 console.log(highTomorrow); // should be 80
``` ```

View File

@ -61,12 +61,12 @@ const HIGH_TEMPERATURES = {
tomorrow: 80 tomorrow: 80
}; };
// change code below this line // Only change code below this line
const today = HIGH_TEMPERATURES.today; const today = HIGH_TEMPERATURES.today;
const tomorrow = HIGH_TEMPERATURES.tomorrow; const tomorrow = HIGH_TEMPERATURES.tomorrow;
// change code above this line // Only change code above this line
console.log(yesterday) // should be not defined console.log(yesterday) // should be not defined
console.log(today); // should be 77 console.log(today); // should be 77
@ -86,12 +86,8 @@ const HIGH_TEMPERATURES = {
tomorrow: 80 tomorrow: 80
}; };
// change code below this line
const { today, tomorrow } = HIGH_TEMPERATURES; const { today, tomorrow } = HIGH_TEMPERATURES;
// change code above this line
console.log(yesterday) // should be not defined console.log(yesterday) // should be not defined
console.log(today); // should be 77 console.log(today); // should be 77
console.log(tomorrow); // should be 80 console.log(tomorrow); // should be 80

View File

@ -67,10 +67,10 @@ const stats = {
average: 35.85 average: 35.85
}; };
// use function argument destructuring // Use function argument destructuring
// change code below this line // Only change code below this line
const half = (stats) => (stats.max + stats.min) / 2.0; const half = (stats) => (stats.max + stats.min) / 2.0;
// change code above this line // Only change code above this line
console.log(stats); // should be object console.log(stats); // should be object
console.log(half(stats)); // should be 28.015 console.log(half(stats)); // should be 28.015

View File

@ -75,9 +75,9 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
/* Alter code below this line */ // Only change code below this line
/* Alter code above this line */ // Only change code above this line
const thermos = new Thermostat(76); // setting in Fahrenheit scale const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C let temp = thermos.temperature; // 24.44 in C
@ -95,8 +95,6 @@ temp = thermos.temperature; // 26 in C
<section id='solution'> <section id='solution'>
```js ```js
/* Alter code below this line */
class Thermostat { class Thermostat {
constructor(fahrenheit) { constructor(fahrenheit) {
this._tempInCelsius = 5/9 * (fahrenheit - 32); this._tempInCelsius = 5/9 * (fahrenheit - 32);
@ -108,7 +106,6 @@ class Thermostat {
this._tempInCelsius = newTemp; this._tempInCelsius = newTemp;
} }
} }
/* Alter code above this line */
const thermos = new Thermostat(76); // setting in Fahrenheit scale const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C let temp = thermos.temperature; // 24.44 in C

View File

@ -58,14 +58,14 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
// change code below this line // Only change code below this line
const bicycle = { const bicycle = {
gear: 2, gear: 2,
setGear: function(newGear) { setGear: function(newGear) {
this.gear = newGear; this.gear = newGear;
} }
}; };
// change code above this line // Only change code above this line
bicycle.setGear(3); bicycle.setGear(3);
console.log(bicycle.gear); console.log(bicycle.gear);
``` ```

View File

@ -54,13 +54,13 @@ tests:
```js ```js
const createPerson = (name, age, gender) => { const createPerson = (name, age, gender) => {
"use strict"; "use strict";
// change code below this line // Only change code below this line
return { return {
name: name, name: name,
age: age, age: age,
gender: gender gender: gender
}; };
// change code above this line // Only change code above this line
}; };
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
``` ```

View File

@ -41,17 +41,14 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
/** // Function that returns a string representing a cup of green tea
* A long process to prepare tea.
* @return {string} A cup of tea.
**/
const prepareTea = () => 'greenTea'; const prepareTea = () => 'greenTea';
/** /*
* Get given number of cups of tea. Given a function (representing the tea type) and number of cups needed, the
* @param {number} numOfCups Number of required cups of tea. following function returns an array of strings (each representing a cup of
* @return {Array<string>} Given amount of tea cups. a specific type of tea).
**/ */
const getTea = (numOfCups) => { const getTea = (numOfCups) => {
const teaCups = []; const teaCups = [];
@ -59,15 +56,12 @@ const getTea = (numOfCups) => {
const teaCup = prepareTea(); const teaCup = prepareTea();
teaCups.push(teaCup); teaCups.push(teaCup);
} }
return teaCups; return teaCups;
}; };
// Add your code below this line // Only change code below this line
const tea4TeamFCC = null;
const tea4TeamFCC = null; // :( // Only change code above this line
// Add your code above this line
console.log(tea4TeamFCC); console.log(tea4TeamFCC);
``` ```

View File

@ -15,7 +15,10 @@ Adding one to a number is not very exciting, but we can apply these principles w
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
Rewrite the code so the global array <code>bookList</code> is not changed inside either function. The <code>add</code> function should add the given <code>bookName</code> to the end of an array. The <code>remove</code> function should remove the given <code>bookName</code> from an array. Both functions should return an array, and any new parameters should be added before the <code>bookName</code> parameter. Rewrite the code so the global array <code>bookList</code> is not changed inside either function. The <code>add</code> function should add the given <code>bookName</code> to the end of the array passed to it and return a new array (list). The <code>remove</code> function should remove the given <code>bookName</code> from the array passed to it.
<strong>Note:</strong> Both functions should return an array, and any new parameters should be added before the <code>bookName</code> parameter.
</section> </section>
## Tests ## Tests
@ -45,22 +48,16 @@ tests:
// the global variable // the global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
/* This function should add a book to the list and return the list */ // Change code below this line
// New parameters should come before bookName
// Add your code below this line
function add (bookName) { function add (bookName) {
bookList.push(bookName); bookList.push(bookName);
return bookList; return bookList;
// Add your code above this line // Change code above this line
} }
/* This function should remove a book from the list and return the list */ // Change code below this line
// New parameters should come before the bookName one
// Add your code below this line
function remove (bookName) { function remove (bookName) {
var book_index = bookList.indexOf(bookName); var book_index = bookList.indexOf(bookName);
if (book_index >= 0) { if (book_index >= 0) {
@ -68,7 +65,7 @@ function remove (bookName) {
bookList.splice(book_index, 1); bookList.splice(book_index, 1);
return bookList; return bookList;
// Add your code above this line // Change code above this line
} }
} }
@ -89,22 +86,13 @@ console.log(bookList);
<section id='solution'> <section id='solution'>
```js ```js
// the global variable // The global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
/* This function should add a book to the list and return the list */
// New parameters should come before the bookName one
// Add your code below this line
function add (bookList, bookName) { function add (bookList, bookName) {
return [...bookList, bookName]; return [...bookList, bookName];
// Add your code above this line
} }
/* This function should remove a book from the list and return the list */
// New parameters should come before the bookName one
// Add your code below this line
function remove (bookList, bookName) { function remove (bookList, bookName) {
const bookListCopy = [...bookList]; const bookListCopy = [...bookList];
const bookNameIndex = bookList.indexOf(bookName); const bookNameIndex = bookList.indexOf(bookName);
@ -112,7 +100,6 @@ function remove (bookList, bookName) {
bookListCopy.splice(bookNameIndex, 1); bookListCopy.splice(bookNameIndex, 1);
} }
return bookListCopy; return bookListCopy;
// Add your code above this line
} }
var newBookList = add(bookList, 'A Brief History of Time'); var newBookList = add(bookList, 'A Brief History of Time');

View File

@ -46,24 +46,17 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
/** // Function that returns a string representing a cup of green tea
* A long process to prepare green tea.
* @return {string} A cup of green tea.
**/
const prepareGreenTea = () => 'greenTea'; const prepareGreenTea = () => 'greenTea';
/** // Function that returns a string representing a cup of black tea
* A long process to prepare black tea.
* @return {string} A cup of black tea.
**/
const prepareBlackTea = () => 'blackTea'; const prepareBlackTea = () => 'blackTea';
/** /*
* Get given number of cups of tea. Given a function (representing the tea type) and number of cups needed, the
* @param {function():string} prepareTea The type of tea preparing function. following function returns an array of strings (each representing a cup of
* @param {number} numOfCups Number of required cups of tea. a specific type of tea).
* @return {Array<string>} Given amount of tea cups. */
**/
const getTea = (prepareTea, numOfCups) => { const getTea = (prepareTea, numOfCups) => {
const teaCups = []; const teaCups = [];
@ -71,16 +64,13 @@ const getTea = (prepareTea, numOfCups) => {
const teaCup = prepareTea(); const teaCup = prepareTea();
teaCups.push(teaCup); teaCups.push(teaCup);
} }
return teaCups; return teaCups;
}; };
// Add your code below this line // Only change code below this line
const tea4GreenTeamFCC = null;
const tea4GreenTeamFCC = null; // :( const tea4BlackTeamFCC = null;
const tea4BlackTeamFCC = null; // :( // Only change code above this line
// Add your code above this line
console.log( console.log(
tea4GreenTeamFCC, tea4GreenTeamFCC,

View File

@ -47,7 +47,7 @@ tests:
```js ```js
// tabs is an array of titles of each site open within the window // tabs is an array of titles of each site open within the window
var Window = function(tabs) { var Window = function(tabs) {
this.tabs = tabs; // we keep a record of the array inside the object this.tabs = tabs; // We keep a record of the array inside the object
}; };
// When you join two windows into one window // When you join two windows into one window
@ -58,7 +58,7 @@ Window.prototype.join = function (otherWindow) {
// When you open a new tab at the end // When you open a new tab at the end
Window.prototype.tabOpen = function (tab) { Window.prototype.tabOpen = function (tab) {
this.tabs.push('new tab'); // let's open a new tab for now this.tabs.push('new tab'); // Let's open a new tab for now
return this; return this;
}; };
@ -67,10 +67,10 @@ Window.prototype.tabClose = function (index) {
// Only change code below this line // Only change code below this line
var tabsBeforeIndex = this.tabs.splice(0, index); // get the tabs before the tab var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
var tabsAfterIndex = this.tabs.splice(index + 1); // get the tabs after the tab var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
// Only change code above this line // Only change code above this line
@ -80,13 +80,13 @@ Window.prototype.tabClose = function (index) {
// Let's create three browser windows // Let's create three browser windows
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
// Now perform the tab opening, closing, and other operations // Now perform the tab opening, closing, and other operations
var finalTabs = socialWindow var finalTabs = socialWindow
.tabOpen() // Open a new tab for cat memes .tabOpen() // Open a new tab for cat memes
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(videoWindow.tabClose(2)) // Close third tab in video window, and join
.join(workWindow.tabClose(1).tabOpen()); .join(workWindow.tabClose(1).tabOpen());
console.log(finalTabs.tabs); console.log(finalTabs.tabs);
``` ```
@ -102,7 +102,7 @@ console.log(finalTabs.tabs);
```js ```js
// tabs is an array of titles of each site open within the window // tabs is an array of titles of each site open within the window
var Window = function(tabs) { var Window = function(tabs) {
this.tabs = tabs; // we keep a record of the array inside the object this.tabs = tabs; // We keep a record of the array inside the object
}; };
// When you join two windows into one window // When you join two windows into one window
@ -113,16 +113,16 @@ Window.prototype.join = function (otherWindow) {
// When you open a new tab at the end // When you open a new tab at the end
Window.prototype.tabOpen = function (tab) { Window.prototype.tabOpen = function (tab) {
this.tabs.push('new tab'); // let's open a new tab for now this.tabs.push('new tab'); // Let's open a new tab for now
return this; return this;
}; };
// When you close a tab // When you close a tab
Window.prototype.tabClose = function (index) { Window.prototype.tabClose = function (index) {
var tabsBeforeIndex = this.tabs.slice(0, index); // get the tabs before the tab var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab
var tabsAfterIndex = this.tabs.slice(index + 1); // get the tabs after the tab var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
return this; return this;
}; };
@ -133,9 +133,9 @@ var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Enter
// Now perform the tab opening, closing, and other operations // Now perform the tab opening, closing, and other operations
var finalTabs = socialWindow var finalTabs = socialWindow
.tabOpen() // Open a new tab for cat memes .tabOpen() // Open a new tab for cat memes
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(videoWindow.tabClose(2)) // Close third tab in video window, and join
.join(workWindow.tabClose(1).tabOpen()); .join(workWindow.tabClose(1).tabOpen());
``` ```
</section> </section>

View File

@ -47,7 +47,6 @@ tests:
```js ```js
function convertHTML(str) { function convertHTML(str) {
// &colon;&rpar;
return str; return str;
} }

View File

@ -65,7 +65,6 @@ tests:
```js ```js
function diffArray(arr1, arr2) { function diffArray(arr1, arr2) {
var newArr = []; var newArr = [];
// Same, same; but different.
return newArr; return newArr;
} }
@ -101,7 +100,6 @@ function diffArray(arr1, arr2) {
Object.keys(h2).forEach(function(e) { Object.keys(h2).forEach(function(e) {
if (!(e in h1)) newArr.push(h2[e]); if (!(e in h1)) newArr.push(h2[e]);
}); });
// Same, same; but different.
return newArr; return newArr;
} }
``` ```

View File

@ -46,7 +46,6 @@ tests:
```js ```js
function dropElements(arr, func) { function dropElements(arr, func) {
// Drop them elements.
return arr; return arr;
} }
@ -65,7 +64,6 @@ dropElements([1, 2, 3], function(n) {return n < 3; });
```js ```js
function dropElements(arr, func) { function dropElements(arr, func) {
// Drop them elements.
while (arr.length && !func(arr[0])) { while (arr.length && !func(arr[0])) {
arr.shift(); arr.shift();
} }

View File

@ -54,7 +54,6 @@ tests:
```js ```js
function truthCheck(collection, pre) { function truthCheck(collection, pre) {
// Is everyone being true?
return pre; return pre;
} }
@ -73,7 +72,6 @@ truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "ma
```js ```js
function truthCheck(collection, pre) { function truthCheck(collection, pre) {
// Does everyone have one of these?
return collection.every(function(e) { return e[pre]; }); return collection.every(function(e) { return e[pre]; });
} }
``` ```

View File

@ -46,7 +46,6 @@ tests:
```js ```js
function destroyer(arr) { function destroyer(arr) {
// Remove all the values
return arr; return arr;
} }
@ -69,7 +68,6 @@ function destroyer(arr) {
[].slice.call(arguments, 1).forEach(function(e) { [].slice.call(arguments, 1).forEach(function(e) {
hash[e] = true; hash[e] = true;
}); });
// Remove all the values
return arr.filter(function(e) { return !(e in hash);}); return arr.filter(function(e) { return !(e in hash);});
} }

View File

@ -43,8 +43,6 @@ tests:
```js ```js
function spinalCase(str) { function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str; return str;
} }
@ -63,8 +61,6 @@ spinalCase('This Is Spinal Tap');
```js ```js
function spinalCase(str) { function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
str = str.replace(/([a-z](?=[A-Z]))/g, '$1 '); str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
return str.toLowerCase().replace(/\ |\_/g, '-'); return str.toLowerCase().replace(/\ |\_/g, '-');
} }

View File

@ -42,7 +42,6 @@ tests:
```js ```js
function steamrollArray(arr) { function steamrollArray(arr) {
// I'm a steamroller, baby
return arr; return arr;
} }

View File

@ -46,7 +46,6 @@ tests:
```js ```js
function whatIsInAName(collection, source) { function whatIsInAName(collection, source) {
// What's in a name?
var arr = []; var arr = [];
// Only change code below this line // Only change code below this line

View File

@ -43,12 +43,11 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
function rot13(str) { // LBH QVQ VG! function rot13(str) {
return str; return str;
} }
// Change the inputs below to test
rot13("SERR PBQR PNZC"); rot13("SERR PBQR PNZC");
``` ```

View File

@ -15,6 +15,23 @@ Return <code>{status: "INSUFFICIENT_FUNDS", change: []}</code> if cash-in-drawer
Return <code>{status: "CLOSED", change: [...]}</code> with cash-in-drawer as the value for the key <code>change</code> if it is equal to the change due. Return <code>{status: "CLOSED", change: [...]}</code> with cash-in-drawer as the value for the key <code>change</code> if it is equal to the change due.
Otherwise, return <code>{status: "OPEN", change: [...]}</code>, with the change due in coins and bills, sorted in highest to lowest order, as the value of the <code>change</code> key. Otherwise, return <code>{status: "OPEN", change: [...]}</code>, with the change due in coins and bills, sorted in highest to lowest order, as the value of the <code>change</code> key.
<table class='table table-striped'><tr><th>Currency Unit</th><th>Amount</th></tr><tr><td>Penny</td><td>$0.01 (PENNY)</td></tr><tr><td>Nickel</td><td>$0.05 (NICKEL)</td></tr><tr><td>Dime</td><td>$0.1 (DIME)</td></tr><tr><td>Quarter</td><td>$0.25 (QUARTER)</td></tr><tr><td>Dollar</td><td>$1 (DOLLAR)</td></tr><tr><td>Five Dollars</td><td>$5 (FIVE)</td></tr><tr><td>Ten Dollars</td><td>$10 (TEN)</td></tr><tr><td>Twenty Dollars</td><td>$20 (TWENTY)</td></tr><tr><td>One-hundred Dollars</td><td>$100 (ONE HUNDRED)</td></tr></table> <table class='table table-striped'><tr><th>Currency Unit</th><th>Amount</th></tr><tr><td>Penny</td><td>$0.01 (PENNY)</td></tr><tr><td>Nickel</td><td>$0.05 (NICKEL)</td></tr><tr><td>Dime</td><td>$0.1 (DIME)</td></tr><tr><td>Quarter</td><td>$0.25 (QUARTER)</td></tr><tr><td>Dollar</td><td>$1 (DOLLAR)</td></tr><tr><td>Five Dollars</td><td>$5 (FIVE)</td></tr><tr><td>Ten Dollars</td><td>$10 (TEN)</td></tr><tr><td>Twenty Dollars</td><td>$20 (TWENTY)</td></tr><tr><td>One-hundred Dollars</td><td>$100 (ONE HUNDRED)</td></tr></table>
See below for an example of a cash-in-drawer array:
```js
[
["PENNY", 1.01],
["NICKEL", 2.05],
["DIME", 3.1],
["QUARTER", 4.25],
["ONE", 90],
["FIVE", 55],
["TEN", 20],
["TWENTY", 60],
["ONE HUNDRED", 100]
]
```
</section> </section>
## Instructions ## Instructions
@ -52,21 +69,9 @@ tests:
```js ```js
function checkCashRegister(price, cash, cid) { function checkCashRegister(price, cash, cid) {
var change; var change;
// Here is your change, ma'am.
return change; return change;
} }
// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]); checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
``` ```

View File

@ -63,7 +63,6 @@ tests:
```js ```js
function palindrome(str) { function palindrome(str) {
// Good luck!
return true; return true;
} }

View File

@ -90,7 +90,6 @@ tests:
```js ```js
function telephoneCheck(str) { function telephoneCheck(str) {
// Good luck!
return true; return true;
} }

View File

@ -14,21 +14,20 @@ function Bird(name) {
this.name = name; this.name = name;
} }
typeof Bird.prototype; // => object typeof Bird.prototype; // yields 'object'
``` ```
Because a <code>prototype</code> is an object, a <code>prototype</code> can have its own <code>prototype</code>! In this case, the <code>prototype</code> of <code>Bird.prototype</code> is <code>Object.prototype</code>: Because a <code>prototype</code> is an object, a <code>prototype</code> can have its own <code>prototype</code>! In this case, the <code>prototype</code> of <code>Bird.prototype</code> is <code>Object.prototype</code>:
```js ```js
Object.prototype.isPrototypeOf(Bird.prototype); Object.prototype.isPrototypeOf(Bird.prototype); // returns true
// returns true
``` ```
How is this useful? You may recall the <code>hasOwnProperty</code> method from a previous challenge: How is this useful? You may recall the <code>hasOwnProperty</code> method from a previous challenge:
```js ```js
let duck = new Bird("Donald"); let duck = new Bird("Donald");
duck.hasOwnProperty("name"); // => true duck.hasOwnProperty("name"); // yields true
``` ```
The <code>hasOwnProperty</code> method is defined in <code>Object.prototype</code>, which can be accessed by <code>Bird.prototype</code>, which can then be accessed by <code>duck</code>. This is an example of the <code>prototype</code> chain. The <code>hasOwnProperty</code> method is defined in <code>Object.prototype</code>, which can be accessed by <code>Bird.prototype</code>, which can then be accessed by <code>duck</code>. This is an example of the <code>prototype</code> chain.
@ -65,7 +64,7 @@ function Dog(name) {
let beagle = new Dog("Snoopy"); let beagle = new Dog("Snoopy");
Dog.prototype.isPrototypeOf(beagle); // => true Dog.prototype.isPrototypeOf(beagle); // yields true
// Fix the code below so that it evaluates to true // Fix the code below so that it evaluates to true
???.isPrototypeOf(Dog.prototype); ???.isPrototypeOf(Dog.prototype);

View File

@ -60,8 +60,6 @@ tests:
<div id='js-seed'> <div id='js-seed'>
```js ```js
/* jshint expr: true */
function House(numBedrooms) { function House(numBedrooms) {
this.numBedrooms = numBedrooms; this.numBedrooms = numBedrooms;
} }