Skip to content

Instantly share code, notes, and snippets.

View NicholasEli's full-sized avatar

Nicholas Eli NicholasEli

View GitHub Profile
function stringPosition(needle, haystack) {
var m = needle.length,
n = haystack.length;
if (!m || !n || m > n) {
return -1;
}
if (m === n) {
return needle === haystack ? 0 : -1;
@NicholasEli
NicholasEli / gist:47f66bb01cdf4e7ff78674aad95987c5
Created April 9, 2018 17:28
Vanilla JS xhttp requst with json
const jsonObject = {
//key values
}
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//on complete
}
}
const position = {
latitude: 45.417224,
longitude: -122.659946
}
const { JSDOM } = require('jsdom')
const jsdom = new JSDOM('<!doctype html><html><body></body></html>')
const { window } = jsdom
global.window = window
@NicholasEli
NicholasEli / gist:0b6ae0cc1a78fe2e8cc0b453704586bc
Created February 20, 2020 22:29
Javascript Reverse Array with String Values
/*
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.
*/
const arr = ["h", "e", "l", "l", "o"]
// Cleaner way to manage state and its handlers
import React, { useState, useMemo } from 'react';
const Home = (props) => {
const [count, { inc, dec }] = useCounter();
return (
<main id="home-component" className="component-container">
<h5>Count {count}</h5>