Skip to content

tomquirk/leethelp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

leethelp

JS helpers for Leetcode and friends

sortObjects

const sortObjects = (arr, key, asc = true) => {
  return arr.sort((a, b) => {
    if (a[key] < b[key]) return asc ? -1 : 1;
    if (a[key] > b[key]) return asc ? 1 : -1;
    return 0;
  });
};

sort

/**
 * Time complexity: O(nlog(n))
 */
const sort = (arr, asc = true) => {
  return arr.sort((a, b) => {
    if (a < b) return asc ? -1 : 1;
    if (a > b) return asc ? 1 : -1;
    return 0;
  });
};

About

JS helpers for Leetcode and friends

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published