Skip to content

Instantly share code, notes, and snippets.

View jokamjohn's full-sized avatar
🏠
Working from home

John Kagga jokamjohn

🏠
Working from home
View GitHub Profile
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() {
(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();
(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) {
// 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
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
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
"use strict";
class HeapSort {
constructor(inputArray) {
this.inputArray = inputArray;
this.heapSize = inputArray.length;
}
main() {
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"
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
<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}