Advertisement
Hiteshw11

Function that takes a list of strings and returns a new list with the order of the elements reversed

Nov 16th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.41 KB | Source Code | 0 0
  1. /*Write a function that takes a list of strings and returns a new list with the order of the elements reversed.
  2. Example:
  3. Input: ["apple", "banana", "cherry"]
  4. Output: ["cherry", "banana", "apple"]*/
  5.  
  6.  
  7. void main()
  8. {
  9.   List<String> names=["apple","banana","cherry"];
  10.   print("The reversed List is ${revList(names)}");
  11.  
  12. }
  13.  
  14. List<String> revList(List<String> names1)
  15. {
  16.   return names1.reversed.toList();
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement