Question: Scala: Write a function called addSub that consumes a List[Int] and produces an Int. The function should add all the elements in even position and

Scala:

Write a function called addSub that consumes a List[Int] and produces an Int. The function should add all the elements in even position and subtract all the elements in odd position. Note that the indexes of the first element of a list is 0 so it is in even position. For example, addSub(List(10, 20, 30, 40)) should be 10 - 20 + 30 40

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!