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 topUSandUK_hits_years_v1(albums: List<Album>): List<Int> { | |
val hits = albums.filter { | |
(it.chartUK == 1 && it.chartUS == 1) | |
} | |
val years = ArrayList<Int>() | |
hits.forEach { | |
years.add(it.year) | |
} | |
return years; | |
} |
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 <T> Collection<T>.filter(predicate: (T) -> Boolean) : List<T> |
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 topUSandUK_v4(albums: List<Album>): List<Album> { | |
return albums.filter { | |
(it.chartUK == 1 && it.chartUS == 1) | |
} | |
} |
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 topUSandUK_v3(albums: List<Album>): List<Album> { | |
val hits = arrayListOf<Album>() | |
albums.forEach { | |
if (it.chartUK == 1 && it.chartUS == 1) { | |
hits.add(it) | |
} | |
} | |
return hits; | |
} |
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 topUSandUK_v2(albums: List<Album>): List<Album> { | |
val hits = arrayListOf<Album>() | |
for (album in albums) { | |
if (album.chartUK == 1 && album.chartUS == 1) { | |
hits.add(album) | |
} | |
} | |
return hits; | |
} |
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 topUSandUK_v1(albums: List<Album>): List<Album> { | |
val hits = arrayListOf<Album>() | |
for (i: Int in 0..albums.count()-1) { | |
if (albums[i].chartUK == 1 && albums[i].chartUS == 1) { | |
hits.add(albums[i]) | |
} | |
} | |
return hits; | |
} |
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
data class Album(val title: String, val year: Int, val chartUK: Int, val chartUS: Int) | |
val albums = listOf( | |
Album("The Dark Side of the Moon", 1973, 2, 1), | |
Album("The Wall", 1979, 3, 1), | |
Album("Wish You Were Here", 1975, 1, 1), | |
Album("Animals", 1977, 2, 3), | |
Album("The Piper at the Gates of Dawn", 1967, 6, 131), | |
Album("The Final Cut", 1983, 1, 6), | |
Album("Meddle", 1971, 3, 70), |
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
<input type="button" value="Calculate" onclick="alert(Kotlin.modules.basic.org.sample.calculateTax(200.0))"> |
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 calculateTax(amount: Double): Double { | |
return amount + amount * 0.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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>This page is manipulated with Kotlin</title> | |
</head> | |
<body> | |
<input type="text" id="email"> | |
<script src="js/lib/kotlin.js"></script> | |
<script src="js/app/basic.js"></script> | |
</body> |