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 bankAccount = makeBankAccount(100); | |
bankAccount.checkBalance(); // 100 | |
bankAccount.withdraw(20); | |
bankAccount.checkBalance(); // 80 |
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 makeBankAccount = balance => ({ | |
withdraw: amount => balance = balance - amount, | |
checkBalance: () => balance | |
}); |
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 Browser | |
import Html exposing (Html, button, div, text) | |
import Html.Events exposing (onClick) | |
main = | |
Browser.sandbox { init = 0, update = update, view = view } | |
type Msg = Increment | Decrement | |
update msg model = |
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
class BankAccount { | |
... | |
public withdraw(amount) { | |
this.balance = this.balance - amount; | |
} | |
... | |
} |
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 withdraw = (balance, amount) => balance - amount; | |
const ATM = (state = {balance: 100, amount: 10}, event) => { | |
switch (event.type) { | |
case 'WITHDRAW': | |
return { | |
...state, | |
balance: withdraw(state.balance, state.amount), | |
}; | |
case 'WITHDRAWAL_AMOUNT': |
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
let balance = 100; | |
balance = balance - 20; |
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 bankAccount = new BankAccount(100); // (this.balance = 100) | |
bankAccount.withdraw(20); // (this.balance = this.balance - 20) |
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
let balance = 100; | |
balance = balance - 20; // Does this represent a withdrawal or something else entirely? |
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
bankAccount.withdraw(20); |
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 square = x => x * x; | |
const sum = (x, y) => x + y; | |
const sumOfSquares = (...nums) => nums.reduce((total, num) => sum(total, square(num)), 0); | |
sumOfSquares(1, 2, 3); // 14 |
NewerOlder