Skip to content

Commit

Permalink
[1] all set
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Vishwak committed Jul 14, 2023
2 parents 0dae602 + 6e355ba commit 9df0d64
Show file tree
Hide file tree
Showing 31 changed files with 254 additions and 21 deletions.
Binary file modified js/functional_programming/.DS_Store
Binary file not shown.
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;
}
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');
}
});
3 changes: 3 additions & 0 deletions js/functional_programming/create-a-javascript-promise.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const makeServerRequest = new Promise((resolve, reject) => {

})
8 changes: 8 additions & 0 deletions js/functional_programming/create-a-module-script.txt
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function subtract(x, y) {
return x - y;
}
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 js/functional_programming/handle-a-fulfilled-promise-with-then.txt
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 js/functional_programming/handle-a-rejected-promise-with-catch.txt
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);
});
4 changes: 4 additions & 0 deletions js/functional_programming/import-a-default-export.txt
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 js/functional_programming/learn-about-functional-programming.txt

This file was deleted.

12 changes: 12 additions & 0 deletions js/functional_programming/mutate-an-array-declared-with-const.txt
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();
16 changes: 16 additions & 0 deletions js/functional_programming/prevent-object-mutation.txt
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();
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!");
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
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!");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const magic = () => new Date();
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'
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];
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
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
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
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
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);
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};
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const sum = (...args) => args.reduce((a, b) => a + b, 0);
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);
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]));
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);
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
};

0 comments on commit 9df0d64

Please sign in to comment.