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 hexToBits = (hex) => hex.map(parseHex).join('') | |
const parseHex = (h) => HexMap[h] | |
const HexMap = { | |
0:'0000', | |
1:'0001', | |
2:'0010', | |
3:'0011', | |
4:'0100', |
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
case class User(name: String, friends: Set[Int] = Set()) { | |
def isDirectFriendOf(user: Int): Boolean = friends.contains(user) | |
def befriend(user: Int): User = copy(friends = friends + user) | |
} | |
case class UserWorld(users: List[User] = Nil) { | |
def befriend(uA: Int, uB: Int): UserWorld = | |
UserWorld(users.updated(uA, users(uA).befriend(uB)) | |
.updated(uB, users(uB).befriend(uA)) | |
) |
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
case class Container(amount: Double = 0.0, connects: Set[Int] = Set()) { | |
def getAmount: Double = amount | |
def addWater(water: Double): Container = copy(amount = water + amount) | |
} | |
case class ContainerWorld(containers: List[Container] = Nil) { | |
def addWater(index: Int, water: Double): ContainerWorld = { | |
ContainerWorld(containers.updated(index, containers(index).addWater(water))) | |
} |
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
case class Container(amount: Double = 0.0, connects: Set[Int] = Set()) { | |
def getAmount: Double = amount | |
def addWater(water: Double): Container = copy(amount = water + amount) | |
} | |
case class ContainerWorld(containers: List[Container] = Nil) { | |
def addWater(index: Int, water: Double): ContainerWorld = { | |
ContainerWorld(containers.updated(index, containers(index).addWater(water))) | |
} |
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
decodeMorse = function(morseCode){ | |
return wordSpliter(morseCode) | |
.map(word => letterSpliter(word)) | |
.map(letters => letterDecoder(letters)) | |
.join(' ') | |
} | |
wordSpliter = function(morseCode){ | |
return morseCode.trim().split(' ') | |
} |