Skip to content

Instantly share code, notes, and snippets.

View BrianJenney's full-sized avatar

jenneyb BrianJenney

View GitHub Profile
// JOIN Parsity.io amigo
// a coding program where we teach you to build software, work with experts and get coached towards your first (software) job!
// Import express module
const express = require('express');
const cors = require('cors');
//whitelist all the domains
// Create an express application
@BrianJenney
BrianJenney / backtrackingTemplate.js
Created October 29, 2022 14:42
recursive templates to make your life easier
const backtrackingProblem = (input) => {
const finalResult = []
const recurse = (curSolution, arg) => {
// base case - does our solution work?
if(isBadSolution(curSolution)) return
// add our final solution
@BrianJenney
BrianJenney / redirectLogic.js
Created July 15, 2022 17:58
This code needs to be reviewed. What are some constructive comments and feedback you could share with the author of this code?
import subroutes from '../routes';
import { addTrailingSlashIfNone } from '../utils/helpers';
/*
function to determine the redirect route based on the currentLocaion
*/
const determineRedirect = (currentLocaion) => {
if (subroutes & seoData) {
/*
a closure gives you access to an outer function's scope from an inner function.
*/
const adder = (initialNum) => {
return(nextNum) => {
return initialNum + nextNum
}
}
const { flattenArr, dataFetcher, createList } = require('./myFunc');
const axios = require('axios');
jest.mock('axios', () => ({
get: jest.fn(),
}));
describe.skip('flattenArr', () => {
it('return a non-nested arr', () => {
const input = [1, 2, 3, 4];
const axios = require('axios');
const flattenArr = (arr) => {
const retVal = [];
const helper = (val) => {
for (let i = 0; i < val.length; i++) {
if (Array.isArray(val[i])) {
helper(val[i]);
} else {
import apiClient from './apiClient';
import ShoppingCart from './ShoppingCart';
const ShoppingCartContainer = ({apiClient}) => {
const [errorMessage, setErrorMessage] = useState(null)
const isLoggedIn = useSelector((state) => state.account.isLoggedIn);
const urlToUse = isLoggedIn ? 'https://api/customercheckout' : 'https://api/guestcheckout';
const addToCartFunction = async (items) => {
const ShoppingCart = () => {
const [errorMessage, setErrorMessage] = useState(null)
const isLoggedIn = useSelector((state) => state.account.isLoggedIn);
const urlToUse = isLoggedIn ? 'https://api/customercheckout' : 'https://api/guestcheckout';
const addToCartFunction = async (items) => {
const { data, errors } = await axios.post(urlToUse, {items});
if(errors){
const Cart = ({items, isLoggedIn, btnCallBack}) => {
if(!isLoggedIn){
return <LoginPrompt/>
}
return(
<div>
<div>
{items.map(({price, name}) => {
const Cart = ({items}) => {
const dispatch = useDispatch()
const isLoggedIn = useSelector((state) => state.account.isLoggedIn)
const clearCart = () => {
dispatch(reduxActionToClearCart())
}
if(!isLoggedIn){