Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@daraxdray
daraxdray / group-objects-by-property.md
Created November 18, 2019 06:16 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@daraxdray
daraxdray / binarySearchTree.js
Created November 6, 2022 18:59 — forked from Prottoy2938/binarySearchTree.js
Binary Search Tree implementation in JavaScript
// A binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
// Left child is always less than it's parent and the right child is always bigger than it's parent.
class Node {
constructor(value) {
this.value = value;
this.right = null;
this.left = null;
}
}