diff --git a/components/FolderTree.js b/components/FolderTree.js index d18efa3..0ff0063 100644 --- a/components/FolderTree.js +++ b/components/FolderTree.js @@ -35,10 +35,11 @@ export default function FolderTree(props) { defaultExpanded={expandedNodes} defaultExpandIcon={} onNodeSelect={(event, nodIds) => { - // TODO: already sorted, impliment binary search - const currentNode = props.flattenNodes.find((aNode) => { - return aNode.id === nodIds; - }); + const currentNode = binaryFind(props.flattenNodes, nodIds); + // const currentNode = props.flattenNodes.find((aNode) => { + // console.log(aNode.id); + // return aNode.id === nodIds; + // }); console.log({ currentNode }); if (currentNode != null && currentNode.routePath != null) { router.push(currentNode.routePath); @@ -52,6 +53,31 @@ export default function FolderTree(props) { ); } +function binaryFind(sourceList, valToFind) { + let leftIndex = 0; + let rightIndex = sourceList.length - 1; + let middleIndex; + while (rightIndex >= leftIndex) { + middleIndex = leftIndex + Math.floor((rightIndex - leftIndex) / 2); + const currentValue = sourceList[middleIndex]; + console.log(currentValue); + // If the element is present at the middle + // itself + if (currentValue.id == valToFind) return currentValue; + + // If element is smaller than mid, then + // it can only be present in left subarray + if (currentValue.id > valToFind) rightIndex = middleIndex - 1; + // Else the element can only be present + // in right subarray + else leftIndex = middleIndex + 1; + } + + // We reach here when element is not + // present in array + return null; +} + function ChevronRightIcon() { return ( Triston Armstrong +

โ—๐Ÿ‘ท This site is under construction ๐Ÿšง ๐Ÿ—๏ธ ๐Ÿšง

@@ -26,6 +26,16 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React
+
+ ๐Ÿƒ Notes + {'|'} + ๐Ÿƒ Playground + {'|'} + ๐Ÿƒ Thai Playground +
+ +
+
@@ -47,7 +57,7 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React
-
+

๐Ÿคน Skills (Click me to fast track to docs)

@@ -71,12 +81,6 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React