Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Scala Programming Question 1: Part A: Split text into list of words You are given text as a string with words that are separated by

Scala Programming

Question 1:

Part A: Split text into list of words

You are given text as a string with words that are separated by whitespces. Write a function splitIntoWords that takes a string and returns a list of words that occur in the string. The order of the words in the list must be same as that in the string. Words should not have any whitespaces in them.

Example

Input: "Hello how are you", Output: List("Hello", "how", "are", "you").

Note that there may be multiple spaces between words. Assume no punctuations or periods are present.

Part B: Extract a sublist from a list

Given a list of string lst, an index i into the list and a length j, extract all the elements in the original list lst(i), ..., lst(i+j-1) into a new list. Handle corner cases by returning an empty list when (a) j <= 0 or (b) i+j is greater than the length of the list lst.

Hint Lookup the Scala list API for the list.slice function

def extractSubList(lst: List[String], i: Int, j: Int): List[String]= { // YOUR CODE HERE }

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

Question

Create websites and blogs

Answered: 1 week ago

Question

=+ Have they changed the way employers view IP?

Answered: 1 week ago