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 port = 3000; | |
const express = require('express'); | |
const app = express(); | |
const getJSONString = (obj) => JSON.stringify(obj, null, 2); | |
app | |
.get('/', (req, res) => { | |
console.log(`Method: ${getJSONString(req.method)}`); | |
console.log(`URL: ${getJSONString(req.url)}`); |
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 http = require('http'); | |
const httpStatus = require('http-status-codes'); | |
const port = 3000; | |
const app = http.createServer(); | |
const getJSONString = (obj) => JSON.stringify(obj, null, 2); | |
app.on('request', (req, res) => { | |
var body = []; |
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
exports.messages = ['Hello', 'This is a message', 'And another message']; |
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 add = (a) => (b) => a + b; | |
const addMore = (a) => (b) => (c) => add(a)(b) + c; | |
console.log(add(2)(4)); | |
console.log(addMore(2)(4)(6)); | |
// 6 | |
// 12 |
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
class Player { | |
play(song) { | |
this.currentlyPlayingSong = song; | |
this.isPlaying = true; | |
} | |
pause() { | |
this.isPlaying = 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
const ninjas = new Set(['Kuma', 'Hattori', 'Yagyu']); | |
const samurai = new Set(['Hattori', 'Oda', 'Tomoe']); | |
const pureNinjas = new Set([...ninjas].filter(ninja => !samurai.has(ninja))); | |
const everyone = new Set([...ninjas, ...samurai]); | |
console.log(pureNinjas.size === 2, 'There’s only one ninja samurai'); | |
console.log(pureNinjas.has('Kuma'), 'Kuma is a true ninja'); | |
console.log(pureNinjas.has('Yagyu'), 'Yagyu is a true ninja'); | |
console.log(everyone.size === 5, 'Do not count twice Hattori, the ninja samurai'); |
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
class NinjaCollection { | |
constructor() { | |
this.ninjas = ['Yoshi', 'Kuma', 'Hattori']; | |
} | |
get firstNinja() { | |
console.log('Getting firstNinja'); | |
return this.ninjas[0]; | |
} | |
set firstNinja(value) { | |
console.log('Setting firstNinja'); |
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
class Person { | |
constructor(name) { | |
this.name = name; | |
} | |
dance() { | |
return true; | |
} | |
} |
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* IdGenerator() { | |
let id = 0; | |
while (true) { | |
yield ++id; | |
} | |
} | |
const idIterator = IdGenerator(); | |
const ninja1 = { id: idIterator.next().value }; |
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 multiMax = (first, ...remainingNumbers) => { | |
const max = remainingNumbers.sort((a, b) => b - a).find(a => a); | |
return first * max; | |
} | |
console.log(multiMax(3, 1, 2, 5, 4)); // 3 * 5 = 15 |