Last active
June 18, 2018 17:44
-
-
Save nickovchinnikov/b13819a8bda89da5d1b0d44e02e3276d to your computer and use it in GitHub Desktop.
This file contains 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 itemsToTable = items => { | |
return items.reduce((prevItem, currentItem) => { | |
const cursor = prevItem.length > 0 ? prevItem.length - 1 : 0 | |
if (!Array.isArray(prevItem[cursor])) { | |
prevItem[cursor] = [] | |
} | |
const currentColumn = cursor >= 0 ? prevItem[cursor] : [] | |
const isEmptyColumn = currentColumn.length === 0 | |
const isWinningHand = currentColumn[0].WinningHand === currentItem.WinningHand | |
if (isEmptyColumn || isWinningHand) { | |
prevItem[cursor].push(currentItem) | |
} | |
if (!isEmptyColumn && !isWinningHand) { | |
prevItem[cursor + 1] = [currentItem] | |
} | |
return prevItem | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment