Skip to content

Instantly share code, notes, and snippets.

View alexandrzavalii's full-sized avatar
🏠
Working from home

alex alexandrzavalii

🏠
Working from home
View GitHub Profile
import React from "react";
import FirstChild from "./FirstChild";
import SecondChild from "./SecondChild";
class DumbosParent extends React.Component {
state = { availableShoes: 6, lollipops: 9 };
render() {
const { availableShoes, lollipops } = this.state;
return (
// DumboParent.js
return (
<Dumbo
availableShoes={availableShoes}
firstChild={clothing => <FirstChild clothing={clothing} lollipops={this.state.lollipops} />}
secondChild={clothing => <SecondChild clothing={clothing} />}
/>
)
// Dumbo.js
@alexandrzavalii
alexandrzavalii / group-objects-by-property.md
Created August 16, 2019 07:23 — 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;
@alexandrzavalii
alexandrzavalii / alphanumericgenerator.js
Last active April 25, 2021 10:56
Alpha numeric id generator
class AlphaNumericIdGenerator {
constructor() {
const alpha = Array.from({ length: 26 }, (_, i) => String.fromCharCode(i + 97))
const numo = Array.from({ length: 10 }, (_, i) => i.toString())
this.alphanumeric = numo.concat(alpha)
this.alphaIndx = this.alphanumeric.reduce((obj, cur, i) => ({ ...obj, [cur]: i }), {});
}
between(after, before) {
this._validate(after);