-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
254 additions
and
21 deletions.
There are no files selected for viewing
Binary file not shown.
9 changes: 9 additions & 0 deletions
9
js/functional_programming/compare-scopes-of-the-var-and-let-keywords.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function checkScope() { | ||
let i = 'function scope'; | ||
if (true) { | ||
let i = 'block scope'; | ||
console.log('Block scope i is: ', i); | ||
} | ||
console.log('Function scope i is: ', i); | ||
return i; | ||
} |
10 changes: 10 additions & 0 deletions
10
js/functional_programming/complete-a-promise-with-resolve-and-reject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const makeServerRequest = new Promise((resolve, reject) => { | ||
// responseFromServer represents a response from a server | ||
let responseFromServer; | ||
|
||
if(responseFromServer) { | ||
resolve('We got the data'); | ||
} else { | ||
reject('Data not received'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const makeServerRequest = new Promise((resolve, reject) => { | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<body> | ||
<!-- Only change code below this line --> | ||
<script type="module" src="index.js"></script> | ||
|
||
<!-- Only change code above this line --> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
js/functional_programming/create-an-export-fallback-with-export-default.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function subtract(x, y) { | ||
return x - y; | ||
} |
17 changes: 17 additions & 0 deletions
17
js/functional_programming/create-strings-using-template-literals.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const result = { | ||
success: ["max-length", "no-amd", "prefer-arrow-functions"], | ||
failure: ["no-var", "var-on-top", "linebreak"], | ||
skipped: ["no-extra-semi", "no-dup-keys"] | ||
}; | ||
function makeList(arr) { | ||
// Only change code below this line | ||
const failureItems = []; | ||
arr.forEach(item => { | ||
failureItems.push(`<li class="text-warning">${item}</li>`); | ||
}); | ||
// Only change code above this line | ||
|
||
return failureItems; | ||
} | ||
|
||
const failuresList = makeList(result.failure); |
14 changes: 14 additions & 0 deletions
14
js/functional_programming/handle-a-fulfilled-promise-with-then.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const makeServerRequest = new Promise((resolve, reject) => { | ||
// responseFromServer is set to true to represent a successful response from a server | ||
let responseFromServer = true; | ||
|
||
if(responseFromServer) { | ||
resolve("We got the data"); | ||
} else { | ||
reject("Data not received"); | ||
} | ||
}); | ||
|
||
makeServerRequest.then(result => { | ||
console.log(result); | ||
}); |
18 changes: 18 additions & 0 deletions
18
js/functional_programming/handle-a-rejected-promise-with-catch.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const makeServerRequest = new Promise((resolve, reject) => { | ||
// responseFromServer is set to false to represent an unsuccessful response from a server | ||
let responseFromServer = false; | ||
|
||
if(responseFromServer) { | ||
resolve("We got the data"); | ||
} else { | ||
reject("Data not received"); | ||
} | ||
}); | ||
|
||
makeServerRequest.then(result => { | ||
console.log(result); | ||
}); | ||
|
||
makeServerRequest.catch(error => { | ||
console.log(error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import subtract from './math_functions.js'; | ||
// Only change code above this line | ||
|
||
subtract(7,4); |
21 changes: 0 additions & 21 deletions
21
js/functional_programming/learn-about-functional-programming.txt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
js/functional_programming/mutate-an-array-declared-with-const.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const s = [5, 7, 2]; | ||
function editInPlace() { | ||
// Only change code below this line | ||
s[0] = 2; | ||
s[1] = 5; | ||
s[2] = 7; | ||
return s; | ||
// Using s = [2, 5, 7] would be invalid | ||
|
||
// Only change code above this line | ||
} | ||
editInPlace(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function freezeObj() { | ||
const MATH_CONSTANTS = { | ||
PI: 3.14 | ||
}; | ||
// Only change code below this line | ||
Object.freeze(MATH_CONSTANTS); | ||
|
||
// Only change code above this line | ||
try { | ||
MATH_CONSTANTS.PI = 99; | ||
} catch(ex) { | ||
console.log(ex); | ||
} | ||
return MATH_CONSTANTS.PI; | ||
} | ||
const PI = freezeObj(); |
6 changes: 6 additions & 0 deletions
6
js/functional_programming/reuse-javascript-code-using-import.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
import {uppercaseString, lowercaseString } from './string_functions.js'; | ||
// Only change code above this line | ||
|
||
uppercaseString("hello"); | ||
lowercaseString("WORLD!"); |
3 changes: 3 additions & 0 deletions
3
js/functional_programming/set-default-parameters-for-your-functions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Only change code below this line | ||
const increment = (number, value = 1) => number + value; | ||
// Only change code above this line |
5 changes: 5 additions & 0 deletions
5
js/functional_programming/use--to-import-everything-from-a-file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as stringFunctions from './string_functions.js'; | ||
// Only change code above this line | ||
|
||
stringFunctions.uppercaseString("hello"); | ||
stringFunctions.lowercaseString("WORLD!"); |
1 change: 1 addition & 0 deletions
1
js/functional_programming/use-arrow-functions-to-write-concise-anonymous-functions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const magic = () => new Date(); |
11 changes: 11 additions & 0 deletions
11
js/functional_programming/use-class-syntax-to-define-a-constructor-function.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Only change code below this line | ||
class Vegetable { | ||
name; | ||
constructor(test) { | ||
this.name = test; | ||
} | ||
} | ||
// Only change code above this line | ||
|
||
const carrot = new Vegetable('carrot'); | ||
console.log(carrot.name); // Should display 'carrot' |
3 changes: 3 additions & 0 deletions
3
js/functional_programming/use-destructuring-assignment-to-assign-variables-from-arrays.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let a = 8, b = 6; | ||
// Only change code below this line | ||
[a,b] = [b,a]; |
11 changes: 11 additions & 0 deletions
11
...onal_programming/use-destructuring-assignment-to-assign-variables-from-nested-objects.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const LOCAL_FORECAST = { | ||
yesterday: { low: 61, high: 75 }, | ||
today: { low: 64, high: 77 }, | ||
tomorrow: { low: 68, high: 80 } | ||
}; | ||
|
||
// Only change code below this line | ||
|
||
const {today: {low: lowToday, high: highToday }} = LOCAL_FORECAST; | ||
|
||
// Only change code above this line |
11 changes: 11 additions & 0 deletions
11
js/functional_programming/use-destructuring-assignment-to-assign-variables-from-objects.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const HIGH_TEMPERATURES = { | ||
yesterday: 75, | ||
today: 77, | ||
tomorrow: 80 | ||
}; | ||
|
||
// Only change code below this line | ||
|
||
const {today: highToday, tomorrow: highTomorrow } = HIGH_TEMPERATURES; | ||
|
||
// Only change code above this line |
11 changes: 11 additions & 0 deletions
11
js/functional_programming/use-destructuring-assignment-to-extract-values-from-objects.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const HIGH_TEMPERATURES = { | ||
yesterday: 75, | ||
today: 77, | ||
tomorrow: 80 | ||
}; | ||
|
||
// Only change code below this line | ||
|
||
const {today, tomorrow} = HIGH_TEMPERATURES; | ||
|
||
// Only change code above this line |
12 changes: 12 additions & 0 deletions
12
..._programming/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const stats = { | ||
max: 56.78, | ||
standard_deviation: 4.34, | ||
median: 34.54, | ||
mode: 23.87, | ||
min: -0.75, | ||
average: 35.85 | ||
}; | ||
|
||
// Only change code below this line | ||
const half = ({max, min}) => (max + min) / 2.0; | ||
// Only change code above this line |
8 changes: 8 additions & 0 deletions
8
...mming/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const source = [1,2,3,4,5,6,7,8,9,10]; | ||
function removeFirstTwo(list) { | ||
// Only change code below this line | ||
const [a,b,...arr] = list; // Change this line | ||
// Only change code above this line | ||
return arr; | ||
} | ||
const arr = removeFirstTwo(source); |
9 changes: 9 additions & 0 deletions
9
js/functional_programming/use-export-to-share-a-code-block.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const uppercaseString = (string) => { | ||
return string.toUpperCase(); | ||
} | ||
|
||
const lowercaseString = (string) => { | ||
return string.toLowerCase() | ||
} | ||
|
||
export {uppercaseString, lowercaseString}; |
21 changes: 21 additions & 0 deletions
21
js/functional_programming/use-getters-and-setters-to-control-access-to-an-object.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Only change code below this line | ||
|
||
class Thermostat { | ||
constructor(fahrenheit) { | ||
this.fahrenheit = fahrenheit; | ||
} | ||
|
||
get temperature() { | ||
return (5 / 9) * (this.fahrenheit - 32); | ||
} | ||
|
||
set temperature(celsius) { | ||
this.fahrenheit = (celsius * 9.0) / 5 + 32; | ||
} | ||
} | ||
// Only change code above this line | ||
|
||
const thermos = new Thermostat(76); // Setting in Fahrenheit scale | ||
let temp = thermos.temperature; // 24.44 in Celsius | ||
thermos.temperature = 26; | ||
temp = thermos.temperature; // 26 in Celsius |
1 change: 1 addition & 0 deletions
1
js/functional_programming/use-the-rest-parameter-with-function-parameters.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const sum = (...args) => args.reduce((a, b) => a + b, 0); |
6 changes: 6 additions & 0 deletions
6
js/functional_programming/use-the-spread-operator-to-evaluate-arrays-in-place.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY']; | ||
let arr2; | ||
|
||
arr2 = [...arr1]; // Change this line | ||
|
||
console.log(arr2); |
4 changes: 4 additions & 0 deletions
4
js/functional_programming/write-arrow-functions-with-parameters.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const myConcat = (arr1, arr2) => arr1.concat(arr2); | ||
|
||
|
||
console.log(myConcat([1, 2], [3, 4, 5])); |
8 changes: 8 additions & 0 deletions
8
js/functional_programming/write-concise-declarative-functions-with-es6.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Only change code below this line | ||
const bicycle = { | ||
gear: 2, | ||
setGear(newGear) { this.gear = newGear} | ||
}; | ||
// Only change code above this line | ||
bicycle.setGear(3); | ||
console.log(bicycle.gear); |
9 changes: 9 additions & 0 deletions
9
...programming/write-concise-object-literal-declarations-using-object-property-shorthand.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const createPerson = (name, age, gender) => { | ||
// Only change code below this line | ||
return { | ||
name, | ||
age, | ||
gender | ||
}; | ||
// Only change code above this line | ||
}; |