Get the deepest descendants matching an optional selector of each element in the set of matched elements.
Installation
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)) | |
} |
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)) |
My favorite sorting algorithm.
A Pen by Gerald Fullam on CodePen.