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 carModels = cars.map((car) -> car.model ); | |
const oldEnough = users.filter((user) -> user.age >= 21 ); |
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
val double = { num:Int -> num * 2 } | |
val square = { num: Int -> | |
val result = num * num | |
// The last expression in a lambda is always considered the return value: | |
result | |
} |
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 double = (num) => num * 2; // Single line has implicit return | |
const square = (num) => { | |
const result = num * num; | |
return result; // Multi line: No implicit return | |
} |
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
fun reformat(str: String, | |
normalizeCase: Boolean = true, | |
upperCaseFirstLetter: Boolean = true, | |
divideByCamelHumps: Boolean = false, | |
wordSeparator: Char = ' ') { | |
... | |
} | |
reformat("SomeString", normalizeCase = false, divideByCamelHumps = true) |
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
/* | |
* JavaScript doesn't support named arguments, | |
* but it is a common pattern to accept | |
* an object as argument for similar purposes. | |
*/ | |
function reformat(str, options) { | |
// Merge default options | |
const defaultOptions = { | |
normalizeCase: true, |
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
fun double(num:Int) { | |
return num * 2 | |
} | |
// Default values | |
fun shout(message: String, postfix = "!!!"): String { | |
return "${message.toUpperCase()}$postfix" | |
} |
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 double(num) { | |
return num * 2; | |
} | |
double(2); // 4 | |
// Default values | |
function shout(message, postfix = "!!!") { | |
return `${message.toUpperCase()}${postfix}`; | |
} |
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 action = "Attacking using a $weapon" | |
const result = "Looks like you will ${user.getFate()}" // curly brackets are only necessary to interpolate expressions |
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 action = `Attacking using a ${weapon}`; | |
const result = `Looks like you will ${user.getFate()}`; |
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
val house = "Stark" | |
val motto = """ | |
Winter | |
is | |
comming | |
""" |