Created
December 28, 2021 22:17
-
-
Save ygorrrteles/6d39ca30d51c5ff30a069bf18b9d0519 to your computer and use it in GitHub Desktop.
find closest number in array dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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