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
//Currying is when you break down a function that takes multiple arguments into a //series of functions that take part of the arguments. | |
//converts a function f of two arguments into a function of one argument that partially applies f. | |
def curry[A,B,C](f: (A,B) => C): A => (B => C) = | |
(a: A) => (b: B) => f(a,b) | |
//> curry: [A, B, C](f: (A, B) => C)A => (B => C) |
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
import express from 'express' | |
import path from 'path' | |
import fs from 'fs' | |
const app = express() | |
app.set("port", process.env.PORT || 3001) | |
// Middleware that serves static file ====================================== | |
app.use('/static', (req, res, next) => { |
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
function Person(name) { | |
var secret = “secret!” | |
this.name = name | |
this.setName = function(newName) { this.name = newName } | |
this.setNameToFoo = function() { this.name = foo } | |
this.getSecret = function() { return secret } | |
} | |
var a = new Person(“Max”) | |
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
var incrementUntil = function(max) { | |
if(num >= max) return num | |
num++ | |
incrementUntil(max) | |
} | |
var num = 0 | |
incrementUntil(3) | |
num //> 3 |
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
num = 0 | |
var myFun = function() { | |
incrementUntil(3) | |
return num | |
} | |
myFun() //> 3 | |
num //> 3 |
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
num = 0 | |
var myFun2 = function() { | |
var num = -1 | |
incrementUntil(3) | |
return num | |
} | |
myFun2() //> -1 ……Why? | |
num //> 3 |
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
const getInfoFromURL = path => { | |
const URL = require(“url”).URL; | |
const myUrl = new URL(path) | |
const pathname = myUrl.pathname | |
const getUsernameFromURL = pathname => { | |
const regex = new RegExp(‘/@’); | |
const username = pathname.split(regex).slice(1)[0] | |
if(!username) { | |
return “Error in parsing: URL needs to be in format://hostname:port/@username” |
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
var multThenAdd = num => { | |
return mul => add => { | |
return num * mul + add | |
} | |
} | |
var timesTwoPlusFour = (num) => multThenAdd(num)(2)(4) | |
timesTwoPlusFour(1) //> 6 | |
timesTwoPlusFour(10) //> 24 |
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
var incrementUntil = function(max) { | |
var inc = function(num) { | |
if(num >= max) return num | |
return inc(num+1) | |
} | |
return (num) => inc(num) | |
} | |
incrementUntil(4)(1) //> 4 | |
incrementUntil(8)(3) //> 8 |
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
var myFun2 = function() { | |
var num = -1 | |
function incrementUntil(max) { | |
if(num >= max) return num | |
num++ | |
incrementUntil(max) | |
} | |
incrementUntil(3) | |
return num | |
} |
OlderNewer