Skip to content

Instantly share code, notes, and snippets.

@ygorrrteles
Created December 28, 2021 22:17
Show Gist options
  • Save ygorrrteles/6d39ca30d51c5ff30a069bf18b9d0519 to your computer and use it in GitHub Desktop.
Save ygorrrteles/6d39ca30d51c5ff30a069bf18b9d0519 to your computer and use it in GitHub Desktop.
find closest number in array dart
void main() {
final list = <int>[1,5,10,11,13,20];
final target =10.50000001;
final closestClickedPoint = list.reduce((value, element){
return (element - target).abs() < (value - target).abs() ? element : value;
});
print(closestClickedPoint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment