Question

Write this program in Scala: Write a function that returns true if a given list of...

Write this program in Scala: Write a function that returns true if a given list of integers is sorted in ascending order.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// An example list.
val positions = List(30, 300, 10, 20, 300)

// Sort Ints from high to low (descending).
val result = positions.sorted
println(result)

// Sort Ints in reverse order (from low to high, ascending).
val result2 = positions.sorted(Ordering.Int.reverse)
println(result2)

// The original list is unchanged.
println(positions)

Add a comment
Know the answer?
Add Answer to:
Write this program in Scala: Write a function that returns true if a given list of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT