Question: Please help me to solve this on scala Write a function that inputs a list of integers and returns all the indices in the original

Please help me to solve this on scala

Please help me to solve this on scala Write a function that

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. ]: def allIndicesDivisibleBy3 (1st: List[Int]): List[Int] = { // YOUR CODE HERE ??? } ]: //BEGIN TESTS val lst1 = List(1,3,5,7,6,9,12,11) val res1 = all IndicesDivisibleBy3(1st1) assert (resl == List(1,4,5,6)) val Ist2 = List(1,5,7,9,11,13,15) val res2 = allIndicesDivisibleBy3 (1st2) assert (res2 == List(3,6) val lst3 = List(1,5,7,11,13) val res3 = allIndicesDivisibleBy3(1st3) assert (res3.length == 0) val 1st4 = List(-3,-6,-9,-12,-15,-18,-21.-24) val res4 - all IndicesDivisibleBy3 (1st4) assert (res4 == List (0,1,2,3,4,5,6,7))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!