Challenge: Appending an Element to a List
Explore how to append an element to a Scala list by duplicating the first item. This lesson helps you practice list manipulation within Scala's collection framework, reinforcing understanding of immutable lists and basic functional operations through hands-on coding.
We'll cover the following...
We'll cover the following...
Problem Statement
You are given a list of elements and you have to append an element to the list which is equivalent to the first element of the same list.
Input
The input is the List list to which you need to append an element.
listhas already been declared for you.
Output
The output will be finalList.
Sample Input
("a","b","c")
Sample Output
("a","b","c","a")
Test Yourself
Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!
Let’s go over the solution review in the next lesson.