2020-02-05 21:33:00 +03:00
|
|
|
## Destructuring Declarations (#1)
|
|
|
|
|
|
|
|
Using `Pairs.kt` as a model, write a function `calculate(n1: Int, n2: Int)`
|
|
|
|
which returns a `Triple` containing a `Boolean` and two `Int`s. If either `n1`
|
2020-04-28 23:39:10 +03:00
|
|
|
or `n2` is less than zero, it returns a `Triple` containing `false` and two
|
|
|
|
zeros. Otherwise, it returns a `Triple` containing:
|
2020-02-05 21:33:00 +03:00
|
|
|
|
2020-12-02 21:45:43 +03:00
|
|
|
+ `true`
|
2020-04-23 15:31:30 +03:00
|
|
|
|
2020-12-02 21:45:43 +03:00
|
|
|
+ The sum of `n1` and `n2`
|
2020-04-23 15:31:30 +03:00
|
|
|
|
2020-12-02 21:45:43 +03:00
|
|
|
+ `n1` multiplied by `n2`
|
2020-02-05 21:33:00 +03:00
|
|
|
|
2020-10-11 19:39:02 +03:00
|
|
|
The starter code contains a `main()` with tests, showing the difference between
|
2020-02-05 21:33:00 +03:00
|
|
|
unpacking the `Triple` using `first`, `second` and `third` versus a
|
2020-10-11 19:39:02 +03:00
|
|
|
destructuring declaration.
|