All files / algorithms/sort/src key.ts

100% Statements 4/4
100% Branches 4/4
100% Functions 2/2
100% Lines 2/2

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

1 2 3 4 55x   9x    
export const sortBy = <Element, Key extends keyof Element>(array: Element[], key: Key): Element[] => {
    // eslint-disable-next-line security/detect-object-injection
    return array.concat().sort((a: Element, b: Element) => (a[key] > b[key] ? 1 : a[key] < b[key] ? -1 : 0));
};