Question: IN SCALA D (6 points) : All List Indices whose Elements are Divisible by 3. 1 Write a function that inputs a list of integers
IN SCALA
D (6 points) : All List Indices whose Elements are Divisible by 3. 1 Write a function that inputs a list of integers and returns all the indices in the original list whose elements are divisible by 3. Note that indices start from 0. Your code must return the indices sorted in ascending order. Restrictions Allowed List API functions: zipWithIndex, zip, filter, map , foldLeft , and foldRight . Not allowed: all other list API functions. Loops of any form, recursion and use of var not allowed. Example Input: List(1, 3, 5, 7, 6, 9, 12, 11) Output: List(1, 4, 5, 6) Note that the returned list is a list of integers whose entries correspond to the indices in the original list. : = { 1 def allIndicesDivisibleBy3(1st: List[Int]): List[Int] 2 // YOUR CODE HERE 3 ??? 4 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
