Тести
Мова сайту: Українська
Українська
English
Русский
Тести з програмування
Вхід
Реєстрація
Тести з програмування
Теорія
Сніпети
Статті
Головна
Android
Ціни
FAQ
Історія Cosmo
Правила та умови сервісу
Політика конфіденційності
Політика щодо файлів cookie
Зворотній Зв’язок
functions
:
Мова контенту: English
Русский
What will be the result of following code execution? object Main extends App { def quiz = { val result = 5 + 6 } println(quiz) }
functions
Given the following code: object Quizful { def main(args: Array[String]) { println(s"Delayed time: ${delayed(time())}") } def time() = { println("Getting time in nano seconds") System.nanoTime } def delayed( t: => Long ) = { println("In delayed method") println("Param: " + t) t } } What will be printed into the console after running this programm?
functions
Try to fix the loop function inside fib so that it returns the correct values for each case in a tail-recursive way. What should the missing expressions for the trivial case and the recursive call be? def fib(n: Int): Int = { @annotation.tailrec def loop(n: Int, prev: Int, cur: Int): Int = if (n <= __ ) prev else loop(n - __, cur, prev + cur) loop(n, 0, 1) }
functions
Take a detailed look at implementation of isSorted function, what would be the result of applying the following anonymous function with array to it? def isSorted[A](as: Array[A], ordering: (A, A) => Boolean): Boolean = { @annotation.tailrec def go(n: Int): Boolean = if (n >= as.length - 1) true else if (ordering(as(n), as(n + 1))) false else go(n + 1) go(0) } isSorted(Array(1, 3, 5, 7), (x: Int, y: Int) => x > y)
functions
Take a detailed look at implementation of isSorted function, what would be the result of applying the following anonymous function with array to it? def isSorted[A](as: Array[A], ordering: (A, A) => Boolean): Boolean = { @annotation.tailrec def go(n: Int): Boolean = if (n >= as.length - 1) true else if (ordering(as(n), as(n + 1))) false else go(n + 1) go(0) } isSorted(Array(7, 5, 1, 3), (x: Int, y: Int) => x < y)
functions
Function composing feeds the output of one function to the input of another function. Look at the implementation of compose and select the correct result of code execution def compose[A, B, C](f: B => C, g: A => B): A => C = a => f(g(a)) def f(b: Int): Int = b / 2 def g(a: Int): Int = a + 2 compose(f, g)(2) compose(g, f)(2)
functions
Take a look at the implementation of the following function, select the correct result: def someFunction[A](list: List[A]): List[A] = list match { case Nil => sys.error("empty list") case Cons(_, t) => t } someFunction(List(1, 2, 3)) Assuming the following code is available for your reference sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A]
functions
Take a look at the implementation of the following function, select the correct result: def someFunction[A](list: List[A]): List[A] = list match { case Nil => sys.error("empty list") case Cons(_, t) => t } someFunction(List(1)) Assuming the following code is available for your reference sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A]
functions
Take a look at the implementation of the following function, select the correct result: def someFunction[A](l: List[A], h: A): List[A] = l match { case Nil => sys.error("empty list") case Cons(_, t) => Cons(h, t) } someFunction(List(1, 2, 3), 3) Assuming the following code is available for your reference sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A]
functions
Given drop function implemented with pattern matching, what is the result of the code execution? def drop[A](l: List[A], n: Int): List[A] = if (n <= 0) l else l match { case Nil => Nil case Cons(_, t) => drop(t, n - 1) } drop(List(1, 2, 3), 1) Assuming the following code is available for your reference sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A]
functions
← Попередня
1
2
3
4
5
Наступна →
Зареєструйся Зараз
або
Підпишись на майбутні тести