Skip to content

Instantly share code, notes, and snippets.

{
"../javascript-algorithms/src/algorithms/math/linked-list": {
"name": "linked-list",
"category": "algorithms",
"subcategory": "math",
"totalFiles": 0,
"filesList": []
}
}
{
"type": "div",
"style": {},
"children": [
{
"type": "div",
"style": {
"backgroundColor": "black",
"borderColor": "hotpink",
"borderWidth": "2px",
function transformAll({ type = '', style = {}, children = [] }) {
const result = { type, style: transformStyleObject(style), children }
if (Array.isArray(result.children)) {
result.children = result.children.map(transformAll)
}
return result
}
function transformAll({ type = '', style = {}, children = [] }) {
const result = { type, style: transformStyleObject(style), children }
if (Array.isArray(result.children)) {
for (let index = 0; index < result.children.length; index++) {
const child = result.children[index]
child.style = transformStyleObject(child.style)
if (Array.isArray(child.children)) {
for (
function transformStyleObject(styleObj) {
const result = {}
const keys = Object.keys(styleObj)
keys.forEach((key) => {
if (key === 'border') {
const { color, width, style } = styleObj.border
if (color) result.borderColor = color
if (width) result.borderWidth = width
if (style) result.borderStyle = style
{
"type": "div",
"style": {},
"children": [
{
"type": "div",
"style": {
"backgroundColor": "black",
"border": {
"color": "hotpink",
import React from 'react'
import callAll from '../utils/callAll'
function MyButton({ children, onClick: onClickProp, ...rest }) {
function onClick(e) {
window.alert(e.currentTarget.name)
}
return (
<button onClick={callAll(onClick, onClickProp)} {...rest}>
import React from 'react'
function MyButton({ children, onClick: onClickProp, ...rest }) {
return (
<button
onClick={(e) => {
window.alert(e.currentTarget.name)
if (onClickProp) {
onClickProp(e)
}
import React from 'react'
function MyButton({ children, ...rest }) {
return (
<button onClick={(e) => window.alert(e.currentTarget.name)} {...rest}>
{children}
</button>
)
}
const compose = (...fns) => (arg) =>
fns.reduceRight((acc, fn) => (fn ? fn(acc) : acc), arg)
const add = (num1) => (num2) => num1 + num2
const multiply = (num1) => (num2) => num1 * num2
const subtract = (num1) => (num2) => num1 - num2
const composedOperations = compose(add(5), multiply(2), subtract(3))
const compute = (arr, initialNum = 0) =>