Skip to content

Instantly share code, notes, and snippets.

View dballowe7912's full-sized avatar

Donald Ballowe dballowe7912

View GitHub Profile
@dballowe7912
dballowe7912 / DataLayer.js
Created July 30, 2023 07:17
React Context Setup
import React, { createContext, useContext, useReducer } from "react";
// Prepares the dataLayer
export const StateContext = createContext();
// Wrap our app and provide the Data layer
export const StateProvider = ({ reducer, initialState, children }) => (
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
function bubbleSort(arr) {
let temp;
let swapped = false
for (let i = 0; i < arr.length; i++) {
// If the current value is greater than its neighbor to the right
if (arr[i] > arr[i + 1]) {
// Swap those values
temp = arr[i];
arr[i] = arr[i + 1];