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 styled from 'styled-components'; | |
const DropDownContainer = styled("div")``; | |
const DropDownHeader = styled("div")``; | |
const DropDownListContainer = styled("div")``; | |
const DropDownList = styled("ul")``; | |
const ListItem = styled("li")``; | |
export default function App() { |
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 (exports) { | |
'use strict'; | |
var bfs = (function () { | |
function buildPath(parents, targetNode) { | |
var result = [targetNode]; | |
while (parents[targetNode] !== null) { | |
targetNode = parents[targetNode]; | |
result.push(targetNode); | |
} | |
return result.reverse(); |
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 (exports) { | |
'use strict'; | |
var dfs = (function () { | |
function hasPath(graph, current, goal) { | |
var stack = []; | |
var visited = []; | |
var node; | |
stack.push(current); | |
visited[current] = true; | |
while (stack.length) { |
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
// Split the array into halves and merge them recursively | |
function mergeSort (arr) { | |
if (arr.length === 1) { | |
// return once we hit an array with a single item | |
return arr | |
} | |
const middle = Math.floor(arr.length / 2) // get the middle item of the array rounded down | |
const left = arr.slice(0, middle) // items on the left side | |
const right = arr.slice(middle) // items on the right side |
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 insertionSort (items) { | |
for (var i = 0; i < items.length; i++) { | |
let value = items[i] | |
// store the current item value so it can be placed right | |
for (var j = i - 1; j > -1 && items[j] > value; j--) { | |
// loop through the items in the sorted array (the items from the current to the beginning) | |
// copy each item to the next one | |
items[j + 1] = items[j] | |
} | |
// the last item we've reached should now hold the value of the currently sorted item |
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
var items = [5,3,7,6,2,9]; | |
function swap(items, leftIndex, rightIndex){ | |
var temp = items[leftIndex]; | |
items[leftIndex] = items[rightIndex]; | |
items[rightIndex] = temp; | |
} | |
function partition(items, left, right) { | |
var pivot = items[Math.floor((right + left) / 2)], //middle element | |
i = left, //left pointer | |
j = right; //right pointer |
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
"use strict"; | |
class HeapSort { | |
constructor(inputArray) { | |
this.inputArray = inputArray; | |
this.heapSize = inputArray.length; | |
} | |
main() { |
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
export const ItemCard = ({toggleEditing, item, image, onChange, index}) => ( | |
<div className="col-md-6 col-lg-3"> | |
<div className="card mb-3"> | |
<img className="card-img-top" src={image}/> | |
<div className="card-body"> | |
{item.isEditing | |
? | |
<div className="mb-4"> | |
<input | |
type="text" |
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
handleItemUpdate = (event, index) => { | |
const target = event.target; | |
const value = target.value; | |
const name = target.name; | |
this.setState({ | |
items: this.state.items.map((item, itemIndex) => { | |
if (itemIndex === index) { | |
return { | |
...item, | |
[name]: value |
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
<div className="card-body"> | |
{item.isEditing | |
? | |
<div className="mb-4"> | |
<input | |
type="text" | |
name="name" | |
className="form-control mb-2 mr-sm-2" | |
placeholder="Item" | |
value={item.name} |