All files / src/helpers findBreakpoint.js

100% Statements 5/5
57.14% Branches 4/7
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14                6x 234x 240x 6x    
/**
 * Finds a number in breakpoints array
 * that provided a suggestion
 * qualifies the most to be used as a value
 * @param {Array<number>} stops
 * @param {number} value
 */
export function findBreakpoint(stops = [], value) {
  const givenBreakpoints = stops && Array.isArray(stops) ? [...stops] : [ stops ]
  const filteredBreakpoints = givenBreakpoints.sort((a, b) => a - b)
                            .filter(stop => stop >= value)
  return (filteredBreakpoints.length ? filteredBreakpoints : stops)[0]
}