Skip to content

Instantly share code, notes, and snippets.

import React from 'react'
export function isComponentWithName (el, name) {
if (typeof name === 'string') {
return React.isValidElement(el) && name === getDisplayName(el)
}
const validRegEx = name instanceof RegExp ? name : new RegExp(name)
return React.isValidElement(el) && validRegEx.test(getDisplayName(el))
}
@geraldfullam
geraldfullam / A-jQuery-plugin-deepest().markdown
Last active September 24, 2019 14:21
jQuery plugin: .deepest()

jQuery plugin: .deepest()

Get the deepest descendants matching an optional selector of each element in the set of matched elements.

A Pen by Gerald on CodePen.

License.

Installation

@geraldfullam
geraldfullam / gist:eb1da11044643b5cb7aee2f802f049b0
Created January 7, 2020 15:08
Cycle array items by random index
function getRandomIndex(len) {
return Math.floor(Math.random() * Math.floor(len));
}
function cycleArray(arr, i) {
return arr.slice(i).concat(arr.slice(0, i))
}
function cycleArrayByRandomIndex() {
return cycleArray(arr, getRandomIndex(arr.length))
@geraldfullam
geraldfullam / Sort by, then by.markdown
Last active January 30, 2020 19:59
Sort by, then by