Dart - I'm all about being explicit and ensuring the expected result is what I want rather than trying to be creative and smart.
String createPhoneNumber(List<int> numbers) { numbers = numbers.takeWhile((num) => num < 10).toList(); if(numbers.length < 10) return null; var result = StringBuffer("("); for(var idx = 0; idx < numbers.length; idx++) { result.write(numbers[idx]); switch(idx) { case 2: result.write(") "); break; case 5: result.write("-"); break; } } return result.toString(); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Dart - I'm all about being explicit and ensuring the expected result is what I want rather than trying to be creative and smart.