Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add koltin sample for website #1351

Merged
merged 1 commit into from Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions website/index/samples/sample.kotlin.txt
@@ -0,0 +1,28 @@
const val POINTS_X_PASS: Int = 15
val EZPassAccounts: MutableMap<Int, Int> = mutableMapOf(1 to 100, 2 to 100, 3 to 100)
val EZPassReport: Map<Int, Int> = EZPassAccounts

// update points credit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use code documentation instead code comments in this case.

fun updatePointsCredit(accountId: Int) {
if (EZPassAccounts.containsKey(accountId)) {
println("Updating $accountId...")
EZPassAccounts[accountId] = EZPassAccounts.getValue(accountId) + POINTS_X_PASS
} else {
println("Error: Trying to update a non-existing account (id: $accountId)")
}
}

fun accountsReport() {
println("EZ-Pass report:")
EZPassReport.forEach{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow the kotlin code style, please put a space before the brace after foreach.

k, v -> println("ID $k: credit $v")
}
}

fun main() {
accountsReport()
updatePointsCredit(1)
updatePointsCredit(1)
updatePointsCredit(5)
accountsReport()
}