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:
@ -54,7 +54,6 @@ tests:
|
||||
|
||||
```js
|
||||
function booWho(bool) {
|
||||
// What is the new fad diet for ghost developers? The Boolean.
|
||||
return bool;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ tests:
|
||||
|
||||
```js
|
||||
function chunkArrayInGroups(arr, size) {
|
||||
// Break it up.
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,6 @@ tests:
|
||||
|
||||
```js
|
||||
function confirmEnding(str, target) {
|
||||
// "Never give up and good luck will find you."
|
||||
// -- Falcor
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ tests:
|
||||
|
||||
```js
|
||||
function bouncer(arr) {
|
||||
// Don't show a false ID to this bouncer.
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,6 @@ tests:
|
||||
|
||||
```js
|
||||
function repeatStringNumTimes(str, num) {
|
||||
// repeat after me
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ tests:
|
||||
|
||||
```js
|
||||
function largestOfFour(arr) {
|
||||
// You can do this!
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,6 @@ tests:
|
||||
|
||||
```js
|
||||
function frankenSplice(arr1, arr2, n) {
|
||||
// It's alive. It's alive!
|
||||
return arr2;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,6 @@ tests:
|
||||
|
||||
```js
|
||||
function truncateString(str, num) {
|
||||
// Clear out that junk in your trunk
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@ tests:
|
||||
|
||||
```js
|
||||
function getIndexToIns(arr, num) {
|
||||
// Find my place in this sorted array.
|
||||
return num;
|
||||
}
|
||||
|
||||
|
@ -61,13 +61,12 @@ tests:
|
||||
```js
|
||||
function filteredArray(arr, elem) {
|
||||
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;
|
||||
}
|
||||
|
||||
// change code here to test different cases:
|
||||
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
|
||||
function filteredArray(arr, elem) {
|
||||
let newArr = [];
|
||||
// change code below this line
|
||||
for (let i = 0; i<arr.length; i++) {
|
||||
if (arr[i].indexOf(elem) < 0) {
|
||||
newArr.push(arr[i]);
|
||||
}
|
||||
}
|
||||
// change code above this line
|
||||
return newArr;
|
||||
}
|
||||
```
|
||||
|
@ -72,9 +72,9 @@ tests:
|
||||
|
||||
```js
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -58,9 +58,9 @@ let user = {
|
||||
};
|
||||
|
||||
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'));
|
||||
|
@ -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);
|
||||
```
|
||||
|
@ -51,9 +51,9 @@ let foods = {
|
||||
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);
|
||||
```
|
||||
|
@ -79,8 +79,8 @@ var testObj = {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var playerNumber; // Change this Line
|
||||
var player = testObj; // Change this Line
|
||||
var playerNumber; // Change this line
|
||||
var player = testObj; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -75,7 +75,6 @@ function switchOfStuff(val) {
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
switchOfStuff(1);
|
||||
|
||||
```
|
||||
|
@ -81,7 +81,6 @@ function testSize(num) {
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testSize(7);
|
||||
```
|
||||
|
||||
|
@ -69,7 +69,6 @@ function testEqual(val) {
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testEqual(10);
|
||||
```
|
||||
|
||||
|
@ -70,7 +70,6 @@ function testGreaterOrEqual(val) {
|
||||
return "Less than 10";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testGreaterOrEqual(10);
|
||||
```
|
||||
|
||||
|
@ -62,7 +62,6 @@ function testNotEqual(val) {
|
||||
return "Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testNotEqual(10);
|
||||
```
|
||||
|
||||
|
@ -68,7 +68,6 @@ function testLessThan(val) {
|
||||
return "55 or Over";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLessThan(10);
|
||||
```
|
||||
|
||||
|
@ -70,7 +70,6 @@ function testLessOrEqual(val) {
|
||||
return "More Than 24";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLessOrEqual(10);
|
||||
|
||||
```
|
||||
|
@ -57,7 +57,6 @@ function testStrict(val) {
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testStrict(10);
|
||||
```
|
||||
|
||||
|
@ -58,7 +58,6 @@ function testStrictNotEqual(val) {
|
||||
return "Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testStrictNotEqual(10);
|
||||
```
|
||||
|
||||
|
@ -85,7 +85,6 @@ function testLogicalAnd(val) {
|
||||
return "No";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLogicalAnd(10);
|
||||
```
|
||||
|
||||
|
@ -89,7 +89,6 @@ function testLogicalOr(val) {
|
||||
return "Inside";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLogicalOr(15);
|
||||
```
|
||||
|
||||
|
@ -61,8 +61,6 @@ function cc(card) {
|
||||
// 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');
|
||||
```
|
||||
|
||||
|
@ -59,7 +59,6 @@ function randomRange(myMin, myMax) {
|
||||
|
||||
}
|
||||
|
||||
// Change these values to test your function
|
||||
var myRandom = randomRange(5, 15);
|
||||
```
|
||||
|
||||
|
@ -66,7 +66,6 @@ function golfScore(par, strokes) {
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change these values to test
|
||||
golfScore(5, 4);
|
||||
```
|
||||
|
||||
|
@ -71,7 +71,6 @@ function testElseIf(val) {
|
||||
return "Between 5 and 10";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testElseIf(7);
|
||||
|
||||
```
|
||||
|
@ -71,7 +71,6 @@ function testElse(val) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testElse(4);
|
||||
|
||||
```
|
||||
|
@ -85,7 +85,6 @@ function orderMyLogic(val) {
|
||||
}
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
orderMyLogic(7);
|
||||
```
|
||||
|
||||
|
@ -99,7 +99,7 @@ var myMusic = [
|
||||
],
|
||||
"gold": true
|
||||
}
|
||||
// Add record here
|
||||
// Add a record here
|
||||
];
|
||||
|
||||
```
|
||||
|
@ -79,7 +79,6 @@ function sequentialSizes(val) {
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
sequentialSizes(1);
|
||||
|
||||
```
|
||||
|
@ -61,7 +61,6 @@ function compareEquality(a, b) {
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
compareEquality(10, "10");
|
||||
```
|
||||
|
||||
|
@ -84,7 +84,6 @@ function lookUpProfile(name, prop){
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change these values to test your function
|
||||
lookUpProfile("Akira", "likes");
|
||||
```
|
||||
|
||||
|
@ -91,9 +91,7 @@ function updateRecords(id, prop, value) {
|
||||
return collection;
|
||||
}
|
||||
|
||||
// Alter values below to test your code
|
||||
updateRecords(5439, "artist", "ABBA");
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -98,7 +98,6 @@ function chainToSwitch(val) {
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
chainToSwitch(7);
|
||||
|
||||
```
|
||||
|
@ -68,7 +68,6 @@ function isLess(a, b) {
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change these values to test
|
||||
isLess(10, 15);
|
||||
```
|
||||
|
||||
|
@ -68,7 +68,6 @@ function caseInSwitch(val) {
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
caseInSwitch(1);
|
||||
|
||||
```
|
||||
|
@ -78,7 +78,6 @@ function trueOrFalse(wasThatTrue) {
|
||||
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
trueOrFalse(true);
|
||||
```
|
||||
|
||||
|
@ -99,7 +99,6 @@ function phoneticLookup(val) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
phoneticLookup("charlie");
|
||||
```
|
||||
|
||||
|
@ -43,9 +43,9 @@ tests:
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
<!-- add your code below -->
|
||||
<!-- Only change code below this line -->
|
||||
|
||||
<!-- add your code above -->
|
||||
<!-- Only change code above this line -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
@ -59,9 +59,7 @@ tests:
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
<!-- add your code below -->
|
||||
<script type="module" src="index.js"></script>
|
||||
<!-- add your code above -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
@ -37,7 +37,16 @@ This new way of creating strings gives you more flexibility to create robust str
|
||||
## 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 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>
|
||||
|
||||
## Tests
|
||||
@ -71,18 +80,13 @@ const result = {
|
||||
function makeList(arr) {
|
||||
"use strict";
|
||||
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
const resultDisplayArray = null;
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
|
||||
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);
|
||||
```
|
||||
|
||||
@ -108,12 +112,7 @@ function makeList(arr) {
|
||||
|
||||
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);
|
||||
```
|
||||
|
||||
|
@ -53,14 +53,14 @@ tests:
|
||||
function printManyTimes(str) {
|
||||
"use strict";
|
||||
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
|
||||
var sentence = str + " is cool!";
|
||||
for (var i = 0; i < str.length; i+=2) {
|
||||
console.log(sentence);
|
||||
}
|
||||
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
|
||||
}
|
||||
printManyTimes("freeCodeCamp");
|
||||
@ -79,15 +79,11 @@ printManyTimes("freeCodeCamp");
|
||||
function printManyTimes(str) {
|
||||
"use strict";
|
||||
|
||||
// change code below this line
|
||||
|
||||
const SENTENCE = str + " is cool!";
|
||||
for (let i = 0; i < str.length; i+=2) {
|
||||
console.log(SENTENCE);
|
||||
}
|
||||
|
||||
// change code above this line
|
||||
|
||||
}
|
||||
printManyTimes("freeCodeCamp");
|
||||
```
|
||||
|
@ -54,11 +54,11 @@ tests:
|
||||
const s = [5, 7, 2];
|
||||
function editInPlace() {
|
||||
'use strict';
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
|
||||
// s = [2, 5, 7]; <- this is invalid
|
||||
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
}
|
||||
editInPlace();
|
||||
```
|
||||
@ -76,13 +76,9 @@ editInPlace();
|
||||
const s = [5, 7, 2];
|
||||
function editInPlace() {
|
||||
'use strict';
|
||||
// change code below this line
|
||||
|
||||
// s = [2, 5, 7]; <- this is invalid
|
||||
s[0] = 2;
|
||||
s[1] = 5;
|
||||
s[2] = 7;
|
||||
// change code above this line
|
||||
}
|
||||
editInPlace();
|
||||
```
|
||||
|
@ -58,10 +58,10 @@ function freezeObj() {
|
||||
const MATH_CONSTANTS = {
|
||||
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 {
|
||||
MATH_CONSTANTS.PI = 99;
|
||||
} catch(ex) {
|
||||
@ -87,10 +87,8 @@ function freezeObj() {
|
||||
const MATH_CONSTANTS = {
|
||||
PI: 3.14
|
||||
};
|
||||
// change code below this line
|
||||
Object.freeze(MATH_CONSTANTS);
|
||||
|
||||
// change code above this line
|
||||
try {
|
||||
MATH_CONSTANTS.PI = 99;
|
||||
} catch(ex) {
|
||||
|
@ -65,12 +65,12 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```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');
|
||||
console.log(carrot.name); // => should be 'carrot'
|
||||
console.log(carrot.name); // Should display 'carrot'
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -54,9 +54,9 @@ tests:
|
||||
|
||||
```js
|
||||
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(b); // should be 8
|
||||
```
|
||||
|
@ -65,12 +65,12 @@ const LOCAL_FORECAST = {
|
||||
tomorrow: { low: 68, high: 80 }
|
||||
};
|
||||
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
|
||||
const lowToday = LOCAL_FORECAST.today.low;
|
||||
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(highToday); // should be 77
|
||||
@ -89,12 +89,8 @@ const LOCAL_FORECAST = {
|
||||
tomorrow: { low: 68, high: 80 }
|
||||
};
|
||||
|
||||
// change code below this line
|
||||
|
||||
const { today: { low: lowToday, high: highToday }} = LOCAL_FORECAST;
|
||||
|
||||
// change code above this line
|
||||
|
||||
console.log(highToday); // should be 77
|
||||
console.log(highTomorrow); // should be 80
|
||||
```
|
||||
|
@ -56,12 +56,12 @@ const HIGH_TEMPERATURES = {
|
||||
tomorrow: 80
|
||||
};
|
||||
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
|
||||
const highToday = HIGH_TEMPERATURES.today;
|
||||
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(highToday); // should be 77
|
||||
@ -81,12 +81,8 @@ const HIGH_TEMPERATURES = {
|
||||
tomorrow: 80
|
||||
};
|
||||
|
||||
// change code below this line
|
||||
|
||||
const { today: highToday, tomorrow: highTomorrow } = HIGH_TEMPERATURES;
|
||||
|
||||
// change code above this line
|
||||
|
||||
console.log(highToday); // should be 77
|
||||
console.log(highTomorrow); // should be 80
|
||||
```
|
||||
|
@ -61,12 +61,12 @@ const HIGH_TEMPERATURES = {
|
||||
tomorrow: 80
|
||||
};
|
||||
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
|
||||
const today = HIGH_TEMPERATURES.today;
|
||||
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(today); // should be 77
|
||||
@ -86,12 +86,8 @@ const HIGH_TEMPERATURES = {
|
||||
tomorrow: 80
|
||||
};
|
||||
|
||||
// change code below this line
|
||||
|
||||
const { today, tomorrow } = HIGH_TEMPERATURES;
|
||||
|
||||
// change code above this line
|
||||
|
||||
console.log(yesterday) // should be not defined
|
||||
console.log(today); // should be 77
|
||||
console.log(tomorrow); // should be 80
|
||||
|
@ -67,10 +67,10 @@ const stats = {
|
||||
average: 35.85
|
||||
};
|
||||
|
||||
// use function argument destructuring
|
||||
// change code below this line
|
||||
// Use function argument destructuring
|
||||
// Only change code below this line
|
||||
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(half(stats)); // should be 28.015
|
||||
|
@ -75,9 +75,9 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```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
|
||||
let temp = thermos.temperature; // 24.44 in C
|
||||
@ -95,8 +95,6 @@ temp = thermos.temperature; // 26 in C
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
|
||||
/* Alter code below this line */
|
||||
class Thermostat {
|
||||
constructor(fahrenheit) {
|
||||
this._tempInCelsius = 5/9 * (fahrenheit - 32);
|
||||
@ -108,7 +106,6 @@ class Thermostat {
|
||||
this._tempInCelsius = newTemp;
|
||||
}
|
||||
}
|
||||
/* Alter code above this line */
|
||||
|
||||
const thermos = new Thermostat(76); // setting in Fahrenheit scale
|
||||
let temp = thermos.temperature; // 24.44 in C
|
||||
|
@ -58,14 +58,14 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
const bicycle = {
|
||||
gear: 2,
|
||||
setGear: function(newGear) {
|
||||
this.gear = newGear;
|
||||
}
|
||||
};
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
bicycle.setGear(3);
|
||||
console.log(bicycle.gear);
|
||||
```
|
||||
|
@ -54,13 +54,13 @@ tests:
|
||||
```js
|
||||
const createPerson = (name, age, gender) => {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
return {
|
||||
name: name,
|
||||
age: age,
|
||||
gender: gender
|
||||
};
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
};
|
||||
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
|
||||
```
|
||||
|
@ -41,17 +41,14 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
/**
|
||||
* A long process to prepare tea.
|
||||
* @return {string} A cup of tea.
|
||||
**/
|
||||
// Function that returns a string representing a cup of green tea
|
||||
const prepareTea = () => 'greenTea';
|
||||
|
||||
/**
|
||||
* Get given number of cups of tea.
|
||||
* @param {number} numOfCups Number of required cups of tea.
|
||||
* @return {Array<string>} Given amount of tea cups.
|
||||
**/
|
||||
/*
|
||||
Given a function (representing the tea type) and number of cups needed, the
|
||||
following function returns an array of strings (each representing a cup of
|
||||
a specific type of tea).
|
||||
*/
|
||||
const getTea = (numOfCups) => {
|
||||
const teaCups = [];
|
||||
|
||||
@ -59,15 +56,12 @@ const getTea = (numOfCups) => {
|
||||
const teaCup = prepareTea();
|
||||
teaCups.push(teaCup);
|
||||
}
|
||||
|
||||
return teaCups;
|
||||
};
|
||||
|
||||
// Add your code below this line
|
||||
|
||||
const tea4TeamFCC = null; // :(
|
||||
|
||||
// Add your code above this line
|
||||
// Only change code below this line
|
||||
const tea4TeamFCC = null;
|
||||
// Only change code above this line
|
||||
|
||||
console.log(tea4TeamFCC);
|
||||
```
|
||||
|
@ -15,7 +15,10 @@ Adding one to a number is not very exciting, but we can apply these principles w
|
||||
|
||||
## 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>
|
||||
|
||||
## Tests
|
||||
@ -45,22 +48,16 @@ tests:
|
||||
// the global variable
|
||||
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 bookName
|
||||
|
||||
// Add your code below this line
|
||||
// Change code below this line
|
||||
function add (bookName) {
|
||||
|
||||
bookList.push(bookName);
|
||||
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 */
|
||||
// New parameters should come before the bookName one
|
||||
|
||||
// Add your code below this line
|
||||
// Change code below this line
|
||||
function remove (bookName) {
|
||||
var book_index = bookList.indexOf(bookName);
|
||||
if (book_index >= 0) {
|
||||
@ -68,7 +65,7 @@ function remove (bookName) {
|
||||
bookList.splice(book_index, 1);
|
||||
return bookList;
|
||||
|
||||
// Add your code above this line
|
||||
// Change code above this line
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,22 +86,13 @@ console.log(bookList);
|
||||
<section id='solution'>
|
||||
|
||||
```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"];
|
||||
|
||||
/* 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) {
|
||||
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) {
|
||||
const bookListCopy = [...bookList];
|
||||
const bookNameIndex = bookList.indexOf(bookName);
|
||||
@ -112,7 +100,6 @@ function remove (bookList, bookName) {
|
||||
bookListCopy.splice(bookNameIndex, 1);
|
||||
}
|
||||
return bookListCopy;
|
||||
// Add your code above this line
|
||||
}
|
||||
|
||||
var newBookList = add(bookList, 'A Brief History of Time');
|
||||
|
@ -46,24 +46,17 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
/**
|
||||
* A long process to prepare green tea.
|
||||
* @return {string} A cup of green tea.
|
||||
**/
|
||||
// Function that returns a string representing a cup of green tea
|
||||
const prepareGreenTea = () => 'greenTea';
|
||||
|
||||
/**
|
||||
* A long process to prepare black tea.
|
||||
* @return {string} A cup of black tea.
|
||||
**/
|
||||
// Function that returns a string representing a cup of black tea
|
||||
const prepareBlackTea = () => 'blackTea';
|
||||
|
||||
/**
|
||||
* Get given number of cups of tea.
|
||||
* @param {function():string} prepareTea The type of tea preparing function.
|
||||
* @param {number} numOfCups Number of required cups of tea.
|
||||
* @return {Array<string>} Given amount of tea cups.
|
||||
**/
|
||||
/*
|
||||
Given a function (representing the tea type) and number of cups needed, the
|
||||
following function returns an array of strings (each representing a cup of
|
||||
a specific type of tea).
|
||||
*/
|
||||
const getTea = (prepareTea, numOfCups) => {
|
||||
const teaCups = [];
|
||||
|
||||
@ -71,16 +64,13 @@ const getTea = (prepareTea, numOfCups) => {
|
||||
const teaCup = prepareTea();
|
||||
teaCups.push(teaCup);
|
||||
}
|
||||
|
||||
return teaCups;
|
||||
};
|
||||
|
||||
// Add your code below this line
|
||||
|
||||
const tea4GreenTeamFCC = null; // :(
|
||||
const tea4BlackTeamFCC = null; // :(
|
||||
|
||||
// Add your code above this line
|
||||
// Only change code below this line
|
||||
const tea4GreenTeamFCC = null;
|
||||
const tea4BlackTeamFCC = null;
|
||||
// Only change code above this line
|
||||
|
||||
console.log(
|
||||
tea4GreenTeamFCC,
|
||||
|
@ -47,7 +47,7 @@ tests:
|
||||
```js
|
||||
// tabs is an array of titles of each site open within the window
|
||||
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
|
||||
@ -58,7 +58,7 @@ Window.prototype.join = function (otherWindow) {
|
||||
|
||||
// When you open a new tab at the end
|
||||
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;
|
||||
};
|
||||
|
||||
@ -67,10 +67,10 @@ Window.prototype.tabClose = function (index) {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
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 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
|
||||
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
|
||||
|
||||
// Only change code above this line
|
||||
|
||||
@ -102,7 +102,7 @@ console.log(finalTabs.tabs);
|
||||
```js
|
||||
// tabs is an array of titles of each site open within the window
|
||||
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
|
||||
@ -113,16 +113,16 @@ Window.prototype.join = function (otherWindow) {
|
||||
|
||||
// When you open a new tab at the end
|
||||
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;
|
||||
};
|
||||
|
||||
// When you close a tab
|
||||
Window.prototype.tabClose = function (index) {
|
||||
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 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
|
||||
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,6 @@ tests:
|
||||
|
||||
```js
|
||||
function convertHTML(str) {
|
||||
// :)
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,6 @@ tests:
|
||||
```js
|
||||
function diffArray(arr1, arr2) {
|
||||
var newArr = [];
|
||||
// Same, same; but different.
|
||||
return newArr;
|
||||
}
|
||||
|
||||
@ -101,7 +100,6 @@ function diffArray(arr1, arr2) {
|
||||
Object.keys(h2).forEach(function(e) {
|
||||
if (!(e in h1)) newArr.push(h2[e]);
|
||||
});
|
||||
// Same, same; but different.
|
||||
return newArr;
|
||||
}
|
||||
```
|
||||
|
@ -46,7 +46,6 @@ tests:
|
||||
|
||||
```js
|
||||
function dropElements(arr, func) {
|
||||
// Drop them elements.
|
||||
return arr;
|
||||
}
|
||||
|
||||
@ -65,7 +64,6 @@ dropElements([1, 2, 3], function(n) {return n < 3; });
|
||||
|
||||
```js
|
||||
function dropElements(arr, func) {
|
||||
// Drop them elements.
|
||||
while (arr.length && !func(arr[0])) {
|
||||
arr.shift();
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ tests:
|
||||
|
||||
```js
|
||||
function truthCheck(collection, pre) {
|
||||
// Is everyone being true?
|
||||
return pre;
|
||||
}
|
||||
|
||||
@ -73,7 +72,6 @@ truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "ma
|
||||
|
||||
```js
|
||||
function truthCheck(collection, pre) {
|
||||
// Does everyone have one of these?
|
||||
return collection.every(function(e) { return e[pre]; });
|
||||
}
|
||||
```
|
||||
|
@ -46,7 +46,6 @@ tests:
|
||||
|
||||
```js
|
||||
function destroyer(arr) {
|
||||
// Remove all the values
|
||||
return arr;
|
||||
}
|
||||
|
||||
@ -69,7 +68,6 @@ function destroyer(arr) {
|
||||
[].slice.call(arguments, 1).forEach(function(e) {
|
||||
hash[e] = true;
|
||||
});
|
||||
// Remove all the values
|
||||
return arr.filter(function(e) { return !(e in hash);});
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,6 @@ tests:
|
||||
|
||||
```js
|
||||
function spinalCase(str) {
|
||||
// "It's such a fine line between stupid, and clever."
|
||||
// --David St. Hubbins
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -63,8 +61,6 @@ spinalCase('This Is Spinal Tap');
|
||||
|
||||
```js
|
||||
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 ');
|
||||
return str.toLowerCase().replace(/\ |\_/g, '-');
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ tests:
|
||||
|
||||
```js
|
||||
function steamrollArray(arr) {
|
||||
// I'm a steamroller, baby
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,6 @@ tests:
|
||||
|
||||
```js
|
||||
function whatIsInAName(collection, source) {
|
||||
// What's in a name?
|
||||
var arr = [];
|
||||
// Only change code below this line
|
||||
|
||||
|
@ -43,12 +43,11 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function rot13(str) { // LBH QVQ VG!
|
||||
function rot13(str) {
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// Change the inputs below to test
|
||||
rot13("SERR PBQR PNZC");
|
||||
```
|
||||
|
||||
|
@ -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.
|
||||
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>
|
||||
|
||||
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>
|
||||
|
||||
## Instructions
|
||||
@ -52,21 +69,9 @@ tests:
|
||||
```js
|
||||
function checkCashRegister(price, cash, cid) {
|
||||
var change;
|
||||
// Here is your change, ma'am.
|
||||
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]]);
|
||||
```
|
||||
|
||||
|
@ -63,7 +63,6 @@ tests:
|
||||
|
||||
```js
|
||||
function palindrome(str) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,6 @@ tests:
|
||||
|
||||
```js
|
||||
function telephoneCheck(str) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -14,21 +14,20 @@ function Bird(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>:
|
||||
|
||||
```js
|
||||
Object.prototype.isPrototypeOf(Bird.prototype);
|
||||
// returns true
|
||||
Object.prototype.isPrototypeOf(Bird.prototype); // returns true
|
||||
```
|
||||
|
||||
How is this useful? You may recall the <code>hasOwnProperty</code> method from a previous challenge:
|
||||
|
||||
```js
|
||||
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.
|
||||
@ -65,7 +64,7 @@ function Dog(name) {
|
||||
|
||||
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
|
||||
???.isPrototypeOf(Dog.prototype);
|
||||
|
@ -60,8 +60,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
/* jshint expr: true */
|
||||
|
||||
function House(numBedrooms) {
|
||||
this.numBedrooms = numBedrooms;
|
||||
}
|
||||
|
Reference in New Issue
Block a user