DEV Community

loading...

Discussion on: Daily Challenge #177 - Supersize Me

Collapse
exts profile image
Lamonte

dart

int superSize(int number) {
  var data = number.toString();
  var dataInt = List<int>();
  for(var n = 0; n < data.length; n++) {
    var val = int.tryParse(data[n]);
    if(val != null) {
      dataInt.add(val);
    }
  }
  dataInt.sort((a, b) => b.compareTo(a));
  return int.tryParse(dataInt.join());
}

I'm sure this could be done shorter.