UNPKG

vis-utils

Version:

Utility functions for data visualization

25 lines (23 loc) 811 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = findEqualUnsorted; /** * Helper function to find the item that matches this value. * Since it assumes the data is unsorted, it does a linear scan O(n). * * @param {Array} array the input array to search * @param {Number} value the value to match against (typically pixels) * @param {Function} accessor applied to each item in the array to get equivalent * value to compare against * @return {Any} The item in the array that has this value or null if not found */ function findEqualUnsorted(array, value) { var accessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (d) { return d; }; return array.find(function (d) { return accessor(d) === value; }); }