25 lines
607 B
Kotlin
25 lines
607 B
Kotlin
import java.time.Instant
|
|
|
|
fun main() {
|
|
// Check if a is in abc
|
|
println('a' in "abc")
|
|
// Check if a is not in abc
|
|
println('a' !in "abc")
|
|
// Check if now is within the bounds, using comparable under the hood
|
|
println(Instant.now() in Instant.MIN..Instant.MAX)
|
|
}
|
|
|
|
/// Playground
|
|
fun isValidIdentifier(s: String): Boolean {
|
|
fun isValidCharacter(ch: Char): Boolean = ch == '_' || ch.isLetterOrDigit()
|
|
if (s.isEmpty() || s[0].isDigit()) {
|
|
return false
|
|
}
|
|
for (ch in s) {
|
|
if (!isValidCharacter(ch)) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|