Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

F (9 points): Convert a list into an indexed list. Write a function to convert a list of strings into an indexed list of strings.

image text in transcribed

F (9 points): Convert a list into an indexed list. Write a function to convert a list of strings into an indexed list of strings. Indices for this particular problem must start at 1. Example Input List("hello", "world", "my", "cat", "is", "grumpy", "today") Output List( ("hello", 1), ("world", 2), ("my", 3), ("cat", 4), ("is", 5), ("grumpy", 6), ("today", 7)) Restrictions You are allowed to use just the basic list operations such as cons of an element to a list (:), concatenation of two lists (++, or ... operators) and list length operations. List API functions length, reverse, map, filter , foldLeft and foldRight are allowed. No other list API functions (specifically use of the function zipWithIndex or zip will result in 0 points for the problem). var, loops or recursion are not allowed. Hint Use foldLeft that accumulate a list of tuples, wherein each tuple has a string and a number. The size of the accumulator + 1 provides you with the "index" of the current element. ]: 1 2 3 def makeIndexedList(lst:List[String]): List[(String, Int)] = { // YOUR CODE HERE ??? } 4

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

Students also viewed these Databases questions