-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.dart
30 lines (27 loc) · 853 Bytes
/
sort.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'dart:io';
void main() async {
//stdout.write("Enter Your Sentence Here : \n");
//var sent = stdin.readLineSync();
File file = new File('D:\\codes\\leetcode\\Untitled_Message\\test.txt');
String sent = await file.readAsString();
if (sent != null) {
//Split the sentence into a list
List<String> sents = sent.split(' ');
var revSent = sents.reversed;
//splice the splitted lists into a new String
String result = '';
revSent.forEach((element) => {
if (result == null)
{result = element}
else
{result = '$result $element'}
});
print(result);
}
var numbers = <String>['one', 'two', 'three', 'four'];
final number = <int>[13, 2, -4, 5];
number.sort();
//print(number);
numbers.sort((a, b) => a.length.compareTo(b.length));
//print(numbers);
}