closestTo method

E closestTo(
  1. E target, [
  2. num difference(
    1. E a,
    2. E b
    )?
])

The closest element E to target.

Example:

[Note.c, Note.e, Note.f.sharp, Note.a].closestTo(Note.g) == Note.f.sharp

Implementation

E closestTo(E target, [num Function(E a, E b)? difference]) =>
    _closestTo(target, difference ?? _difference);