This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"../javascript-algorithms/src/algorithms/math/linked-list": { | |
"name": "linked-list", | |
"category": "algorithms", | |
"subcategory": "math", | |
"totalFiles": 0, | |
"filesList": [] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "div", | |
"style": {}, | |
"children": [ | |
{ | |
"type": "div", | |
"style": { | |
"backgroundColor": "black", | |
"borderColor": "hotpink", | |
"borderWidth": "2px", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "div", | |
"style": {}, | |
"children": [ | |
{ | |
"type": "div", | |
"style": { | |
"backgroundColor": "black", | |
"border": { | |
"color": "hotpink", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => |