Skip to content

Instantly share code, notes, and snippets.

View cassiozen's full-sized avatar
:atom:

Cassio Zen cassiozen

:atom:
View GitHub Profile
val coordinates = arrayOf(5, 10, 15)
val (x, y, z) = coordinates
const coordinates = [5, 10, 15];
const [x, y, z] = coordinates;
// mapOf is the read-only version of mutableMapof
val colors = mapOf(
"red" to 0xff0000,
"green" to 0x00ff00,
"blue" to 0x0000ff
)
val updatedColors = colors.plus("teal" to 0x008080) // doesn't change the original - it returns a new map
// listOf is the read-only version of mutableListof
val colors = mutableMapOf(
"red" to 0xff0000,
"green" to 0x00ff00,
"blue" to 0x0000ff,
"cyan" to 0x00ffff,
"magenta" to 0xff00ff,
"yellow" to 0xffff00
)
colors.contains("yellow") // true
colors.get("yellow") // 0xffff00
const colors = {
"red": 0xff0000,
"green": 0x00ff00,
"blue": 0x0000ff,
"cyan": 0x00ffff,
"magenta": 0xff00ff,
"yellow": 0xffff00
};
colors.hasOwnProperty("yellow"); // true
colors.yellow; // 0xffff00
val houses = mutableListOf("Stark", "Lannister", "Tyrell", "Arryn", "Targaryen", "Martell", "Baratheon")
houses[2] // "Tyrell"
houses.add("Martell")
houses.size //7
const houses = [ "Stark", "Lannister", "Tyrell", "Arryn", "Targaryen", "Baratheon" ];
houses[2]; // "Tyrell"
houses.push("Martell");
houses.length; //7
for (i in 1..10) {
print(i)
}
// 1 2 3 4 5 6 7 8 9 10
val places = listOf("New York", "Paris", "Rio")
for (place in places) {
println("I Love $place")
}
for (let i = 1; i<=10; i++) {
console.log(i);
}
// 1 2 3 4 5 6 7 8 9 10
const places = ["New York", "Paris", "Rio"];
for (const place of places) {
console.log(`I Love ${place}`);
}
when(selectedFruit) {
"orange" -> print("Oranges are 59 cents a pound.")
"apple" -> print("Apples are 32 cents a pound.")
"cherry" -> print("Cherries are one dollar a pound.")
"mango", "papaya" -> print("Mangoes and papayas are 3 dollars a pound.")
else -> print("Sorry, we are out of $selectedFruit.")
}