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 express = require('express'); | |
| const bodyParser = require('body-parser') | |
| const app = express() | |
| const PORT = 3000; | |
| app.use( express.static('public') ) | |
| // parse application/x-www-form-urlencoded | |
| app.use(bodyParser.urlencoded({ extended: 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 saySomething( message, name ) { | |
| console.log (message + " " + name + "!") | |
| } | |
| saySomething("Hi", "juanma") // "Hi juanma!" | |
| saySomething("Bye", "juanma") // "Bye juanma!" | |
| var sayHi = saySomething.bind(null, "Hi"); | |
| typeof sayHi === 'function' // true | |
| sayHi("juanma") // "Hi juanma!" |
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 fs = require("fs") | |
| fs.readFile('test.txt', 'utf-8', (err, contentFile) => { | |
| setTimeout( ()=> { | |
| contentFile = contentFile.toUpperCase(); | |
| fs.writeFile('output.txt', contentFile, (err) => { | |
| console.log("file written") |
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 shuffleAndGroup (students, sizeGroups = 2) { | |
| var shuffled = students.reduce( (acc, item, i, array) => { | |
| var random = Math.floor(Math.random() * array.length); | |
| array[i] = array.splice(random,1,item)[0] | |
| return array | |
| },[]) | |
| var grouped = shuffled.reduce((acc, current, index, array) => { | |
| if (index % sizeGroups) { |
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 name = "juanma"; | |
| var handler = () => `handling things for ${this.name}...`; | |
| var theProtoObj = { | |
| location: "barcelona", | |
| toString() { | |
| return `I'm super!!` | |
| } | |
| } |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>First Component</title> | |
| </head> | |
| <body> | |
| <!-- container node --> | |
| <div id="app"></div> |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>First Component</title> | |
| </head> | |
| <body> | |
| <!-- container node --> | |
| <div id="app"></div> |
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 User ( name, username ) { | |
| var password = User.generatePassword(15); | |
| this.name = name; | |
| this.username = username; | |
| this.password = User.encryptPassword( password ); | |
| console.log("Your password is : " + password) |
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
| # Generators - ES2015 | |
| http://riadbenguella.com/how-es6-generators-are-changing-how-we-write-javascript/ | |
| Generators are special functions that can be run, paused and resumed at different stages of their execution, thanks to the special keyword `yield`. | |
| ```javascript | |
| function* myGenerator() { | |
| yield 'first'; | |
| let input = yield 'second'; |