Scala Programming: Triplicate each element immediately next to the given list of integers
Write a Scala program to triplicate each element immediately next to the given list of integers.
Sample Solution:
Scala Code:
Sample Output:
Original List: List(1, 2, 3, 3, 4, 5, 6, 7) New list after triplicating each element immediately next to the said list: List(1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7)
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to flatten a given List of Lists, nested list structure.
Next: Write a Scala program to add each element n times to a given list of integers.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics