Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,955 questions

51,897 answers

573 users

How to find the largest and smallest number in a list with Dart

3 Answers

0 votes
import 'dart:math';

main() {
    var list = [2, 6, 9, 7, 1, 3, 5];
  
    print(list.reduce(max));
  
    print(list.reduce(min)); 
}




/*
run:

9
1

*/

 



answered Oct 20, 2022 by avibootz
0 votes
main() {
    var list = [2, 6, 9, 7, 1, 3, 5];
  
    list.sort();

    print(list.first);
    print(list.last);
}




/*
run:

9
1

*/

 



answered Oct 20, 2022 by avibootz
0 votes
main() {
    var list = [2, 6, 9, 7, 1, 3, 5];
  
    var largest_value = list[0];
    var smallest_value = list[0];

    list.forEach((element) => {
        if (element > largest_value) {largest_value = element},
        if (element < smallest_value) {smallest_value = element},
    });

    print("Smallest value = ${smallest_value}");
    print("Largest value = ${largest_value}");
}




/*
run:

Smallest value = 1
Largest value = 9

*/

 



answered Oct 20, 2022 by avibootz
...