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 path = require('path'); | |
const webpack = require('webpack'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
module.exports = (env, options) => ({ | |
optimization: { |
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 schools = [ | |
{ name: "St. Marcellinus Secondary School", address: "730 Courtneypark Drive West" }, | |
{ name: "Sir William Mulock S.S.", address: "705 Columbus Way" }, | |
{ name: "George Harvey Collegiate Institute", address: "1700 Keele St" }, | |
{ name: "Dr. G.W. Williams S.S.", address: "39 Dunning Ave." }, | |
{ name: "Weston Collegiate Institute", address: "100 Pine St" } | |
]; | |
const _pipe = (a, b) => (arg) => b(a(arg)); | |
const pipe = (...ops) => ops.reduce(_pipe); |
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 _pipe = (a, b) => (arg) => b(a(arg)); | |
const pipe = (...ops) => ops.reduce(_pipe) | |
const calcTotalWithTax = pizzaCost => pizzaCost * 1.13 | |
const costForTwo = itemCost => Math.round(itemCost/2 * 100) / 100 | |
const cadToUSD = (cad) => Math.round(cad * 0.753653*100)/100; | |
const costPerPersonUsd = pipe(calcTotalWithTax, costForTwo, cadToUSD); | |
console.log(`You have to pay $ ${costPerPersonUsd(5)} US.`); // You have to pay $2.13 in usd | |
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 _pipe = (a, b) => (arg) => b(a(arg)); | |
// Refactored | |
const pipe = (...ops) => ops.reduce(_pipe) |
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
// Utilize the previous pipe function that accepts only two functions | |
const _pipe = (a, b) => (arg) => b(a(arg)); | |
// The rest parameters creates an array of operations | |
const pipe = (...ops) => { | |
// Iterate over the array of operations | |
// By using reduce, merge all operations into a single bundle | |
let bundle = ops.reduce((prevOp, nextOp) => { | |
return _pipe(prevOp,nextOp); |
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 pipe = (op1, op2) => (arg) => op2(op1(arg)); |
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 pipe = (op1, op2) => { | |
return (arg) => { | |
const result1 = op1(arg); | |
return op2(result1); | |
} | |
} |
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
// First calculate the total cost of the pizza including tax | |
const calcTotalWithTax = pizzaCost => pizzaCost * 1.13 // Here in Toronto, tax is 13% | |
// Then calculate the cost of pizza for two people | |
const costForTwo = itemCost => Math.round(itemCost/2 * 100) / 100 | |
// implement pipe function | |
// the pipe function accepts only two | |
// operations | |
const pipe = (op1, op2) => { |
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
VariableObject: { | |
x: 2, //these are arguments | |
y: 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
VariableObject : { | |
/* no argument for the global context */ | |
minusNum: pointer to function minusNum, | |
addNum: pointer to function sum | |
} |
NewerOlder