This file contains hidden or 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
| let x = [1,2,3,4,5]; | |
| let y = []; | |
| for(let i = 0; i < x.length; i++) | |
| if(x[i] % 2 == 0) | |
| y.push(x[i]*2); | |
| else | |
| continue; | |
| console.log(y); |
This file contains hidden or 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
| let x = [1,2,3,4,5]; | |
| let y = x.map ( element => element*2 ); | |
| console.log(y); | |
| // => [2,4,6,8,10] |
This file contains hidden or 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
| let x = [1,2,3,4,5]; | |
| let y = []; | |
| for(let i = 0; i < x.length; i ++) | |
| y[i] = x[i]*2; | |
| console.log(y); | |
| // => [2,4,6,8,10] |
This file contains hidden or 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
| let x = 5; | |
| let expected = 8; | |
| console.log(`Content of variable x is: ${x} and expected is ${expected}`); | |
| // => Content of variable x is: 5, and expected is 8 |
This file contains hidden or 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
| let x = 5; | |
| let expected = 8; | |
| console.log('Content of variable x is: ' + x + ', and expected is ' + expected); | |
| // => Content of variable x is: 5, and expected is 8 |
This file contains hidden or 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
| const PRECISION = 0.2; // Often called a Delta | |
| function isValid(time) { // Ensures 1 second has elapsed | |
| const expected = 1; | |
| // We only assert this : (expected - precision) <= time <= (expected + precision) | |
| return (expected - PRECISION <= time) && (expected + PRECISION >= time); | |
| } | |
| console.log(isValid(1.105)); |
This file contains hidden or 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
| var torchRunning = false; | |
| var startTime = new Date(); | |
| function sleep(milliseconds) { // A basic sleep implementation to "pause" the current thread | |
| var start = new Date().getTime(); | |
| for (var i = 0; i < 1e7; i++) { | |
| if ((new Date().getTime() - start) > milliseconds){ | |
| break; | |
| } | |
| } |
This file contains hidden or 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
| var lightPlugged = false; | |
| function switchLight() | |
| { | |
| lightPlugged = !lightPlugged; | |
| } | |
| console.log( lightPlugged ? 'Light is on':'Light is off'); | |
| // => Light is off |
This file contains hidden or 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
| var lightPlugged = false; | |
| function switchLight() | |
| { | |
| if(lightPlugged == false) | |
| lightPlugged = true; | |
| else | |
| lightPlugged = false; | |
| } |
This file contains hidden or 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
| function databaseCrashed() { | |
| return true; | |
| } | |
| function leaveBuilding() { | |
| console.log('We are safe'); | |
| } | |
| function stayInBuilding() { | |
| console.log('We are working hard in here'); |