Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to solve by using scala C: All List Elements That are Greater Than Their Index (6 points) Write a list function that

Please help me to solve by using scala

image text in transcribed

C: All List Elements That are Greater Than Their Index (6 points) Write a list function that inputs a list of integers 1st and outputs a list consisting of all those elements in Ist whose values are strictly greater than their indices. Indices of elements start at 0 and go upto length of list -1. The order of the elements in the original list must be preserved in the returned list. Restrictions . You may use these list API functions: zip, zipWithIndex (read documentation), map, foldLeft , foldRight and filter. No other list API functions are allowed. Use of loops, var, recursion not allowed. Example Input: List(1, 2, 2, -2, 4, 6,8) Output: List(1, 2, 6, 8) Note that elements 1 (index 0), 2 (index 1), 6 (index 5) and 8 (index 6) are returned. ]: def listElementsGreaterThanIndex(1st: List[Int]): List[Int] = { // YOUR CODE HERE ??? } 1: val lsti = List(1,2,2,-2,4,6,8) val res1 = listElementsGreaterThanIndex (lsti) assert( resl == List(1,2,6,8)) val 1st2 = List(-1,-2,-3,-4,-5,-6) val res2 = listElementsGreaterThanIndex(1st2) assert( res2.length == 0) val 1st3 - List(1,2,3,4,5,6,7,8) val res3 = listElementsGreaterThan Index (1st3) assert( res 3 == lst3) val 1st4 = List(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3) val res4 = listElementsGreaterThanIndex(1st4) assert (res4 == List(10, 9, 8, 7, 6)) passed (6)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions