Skip to content

Instantly share code, notes, and snippets.

View cassiozen's full-sized avatar
:atom:

Cassio Zen cassiozen

:atom:
View GitHub Profile
const carModels = cars.map((car) -> car.model );
const oldEnough = users.filter((user) -> user.age >= 21 );
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
}
const double = (num) => num * 2; // Single line has implicit return
const square = (num) => {
const result = num * num;
return result; // Multi line: No implicit return
}
fun reformat(str: String,
normalizeCase: Boolean = true,
upperCaseFirstLetter: Boolean = true,
divideByCamelHumps: Boolean = false,
wordSeparator: Char = ' ') {
...
}
reformat("SomeString", normalizeCase = false, divideByCamelHumps = true)
/*
* 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,
fun double(num:Int) {
return num * 2
}
// Default values
fun shout(message: String, postfix = "!!!"): String {
return "${message.toUpperCase()}$postfix"
}
function double(num) {
return num * 2;
}
double(2); // 4
// Default values
function shout(message, postfix = "!!!") {
return `${message.toUpperCase()}${postfix}`;
}
const action = "Attacking using a $weapon"
const result = "Looks like you will ${user.getFate()}" // curly brackets are only necessary to interpolate expressions
const action = `Attacking using a ${weapon}`;
const result = `Looks like you will ${user.getFate()}`;
val house = "Stark"
val motto = """
Winter
is
comming
"""