Skip to content

Instantly share code, notes, and snippets.

View allexysleeps's full-sized avatar

Oleksii Shuliev allexysleeps

  • Amsterdam, Netherlands
View GitHub Profile
@allexysleeps
allexysleeps / js
Created January 30, 2020 11:21
shuffle list js
const getRandNum = (range) => Math.floor(Math.random() * range)
const shuffleList = (list) => {
const len = list.length
for (let i = 0; i < len; i++) {
const idx = getRandNum(len - i)
const last = len - i - 1
const tmp = list[last]
list[last] = list[idx]
list[idx] = tmp
const flattenChildren = (children) => children
.reduce(
(flattenedNextLevelChildren, child) => [...flattenedNextLevelChildren, ...child.children],
[]
)
function getTreeWidth(tree) {
let width = 1
if (!tree.children.length) {
return width