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
val coordinates = arrayOf(5, 10, 15) | |
val (x, y, z) = coordinates |
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 coordinates = [5, 10, 15]; | |
const [x, y, z] = coordinates; |
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
// 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 |
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
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 |
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 colors = { | |
"red": 0xff0000, | |
"green": 0x00ff00, | |
"blue": 0x0000ff, | |
"cyan": 0x00ffff, | |
"magenta": 0xff00ff, | |
"yellow": 0xffff00 | |
}; | |
colors.hasOwnProperty("yellow"); // true | |
colors.yellow; // 0xffff00 |
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
val houses = mutableListOf("Stark", "Lannister", "Tyrell", "Arryn", "Targaryen", "Martell", "Baratheon") | |
houses[2] // "Tyrell" | |
houses.add("Martell") | |
houses.size //7 |
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 houses = [ "Stark", "Lannister", "Tyrell", "Arryn", "Targaryen", "Baratheon" ]; | |
houses[2]; // "Tyrell" | |
houses.push("Martell"); | |
houses.length; //7 |
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
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") | |
} |
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
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}`); | |
} |
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
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.") | |
} |