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
/** | |
* Used as a wrapper for data that is exposed via a LiveData that represents an event. | |
*/ | |
open class Event<out T>(private val content: T) { | |
var hasBeenHandled = false | |
private set // Allow external read but not write | |
/** | |
* Returns the content and prevents its use again. |
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
function fabionanci(n){ | |
const dataFabionanci = []; | |
for (let i = 0; i <= n; i++){ | |
if(i < 2){ | |
dataFabionanci.push(i); | |
}else{ | |
dataFabionanci.push(dataFabionanci[i-1] + dataFabionanci [i - 2]); | |
} | |
} |
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
fun kangaroo(x1: Int, v1: Int, x2: Int, v2: Int): String { | |
// Write your code here | |
var x1Ex = x1 | |
var v1Ex = v1 | |
var x2Ex = x2 | |
var v2Ex = v2 | |
for(i in 0..1000){ | |
if ((x1Ex + v1Ex) == (x2Ex + v2Ex)){ | |
return@kangaroo "YES" |
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 name: String? = "Renren" | |
val length = name?.let { | |
println("Name is not null: $it") | |
it.length | |
} ?: 0 | |
// Output: Name is not null: Renren | |
// length = 4 |
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
data class Person(val name: String, var age: Int) | |
val person = Person("Renren", 22) | |
with(person) { | |
println("Name: $name") | |
println("Age: $age") | |
age += 1 | |
} | |
// Output: | |
// Name: Renren |
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
class Person { | |
var name: String = "" | |
var age: Int = 0 | |
} | |
val person = Person().apply { | |
name = "R AL" | |
age = 22 | |
} |
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 result = run { | |
val a = 10 | |
val b = 20 | |
a + b | |
} | |
println("Result: $result") | |
// Output: Result: 30 |
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 numbers = mutableListOf(1, 2, 3) | |
val doubled = numbers.also { | |
it.add(4) | |
it.mapInPlace { num -> num * 2 } | |
} | |
println("Original List: $numbers") | |
println("Doubled List: $doubled") | |
// Output: | |
// Original List: [1, 2, 3, 4] |
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
// 3. Inisialisasi variabel jumlah = 0 | |
// Untuk setiap nilai i dari 8 sampai 1 dengan langkah -1 | |
// Tambahkan nilai i ke dalam jumlah | |
// Tampilkan jumlah | |
// CODE: | |
#include <iostream> | |
using namespace std; |
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
sealed class Resource<T>(val data: T? = null, val message: String? = null) { | |
class Success<T>(data: T) : Resource<T>(data) | |
class Loading<T>(data: T? = null) : Resource<T>(data) | |
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message) | |
} |
OlderNewer