All files / src/functions sortBuffers.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11

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 15 16 17 18 19 20 21 22 23 24    2x       7x 2x     5x 12x   5x 5x 16x 16x     5x     2x  
import {ITicker, ImarketCodes} from '../interfaces';
 
const sortBuffers = (
  buffers: ITicker[],
  sortOrder: ImarketCodes[],
): ITicker[] | undefined => {
  if (buffers.length === 0 || sortOrder.length === 0) {
    return undefined;
  }
 
  const tickerMap: {[code: string]: ITicker} = {};
  buffers.forEach(ticker => (tickerMap[ticker.code] = ticker));
 
  const result: ITicker[] = [];
  sortOrder.forEach(({market}) => {
    const ticker = tickerMap[market];
    if (ticker) result.push(ticker);
  });
 
  return result;
};
 
export default sortBuffers;