split_string_to_list.gravity 330 B

1234567891011121314151617
  1. #unittest {
  2. name: "Split() with empty argument Test";
  3. error: NONE;
  4. result: true;
  5. };
  6. func main () {
  7. var s = "123456789"
  8. var list = s.split("")
  9. var sum = list.reduce(0, func(num1, num2) {
  10. return num1.Int()+num2.Int()
  11. })
  12. // Check expected just to make sure the loop actually ran
  13. return sum == 45 and list.count == 9
  14. }