Skip to content

Instantly share code, notes, and snippets.

View jwill9999's full-sized avatar
💭
working

Jason Williams jwill9999

💭
working
View GitHub Profile
@jwill9999
jwill9999 / action.js
Last active June 26, 2017 19:43
action.js
import axios from 'axios';
import {AUTH_USER, UNAUTH_USER, AUTH_ERROR} from './types';
import authError from './error';
const ROOT_URL = 'http://localhost:3000/'; // url to api
export default function signinUser(email,password) {
@jwill9999
jwill9999 / reducer.js
Created June 26, 2017 19:46
reducer example
import { AUTH_USER, UNAUTH_USER, AUTH_ERROR } from '../actions/types.js'; // types
export default function (state = {}, action) {
switch (action.type) { //set up switch
case AUTH_USER:
return { ...state, error: "", authenticated: true }; // return previous state as spread operator plus updated state
case UNAUTH_USER:
return { ...state, authenticated: false };
case AUTH_ERROR:
return { ...state, error: action.payload };
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:14
Sum All Numbers In a Range
/*
We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.
The lowest number will not always come first.
*/
function sumAll(arr) {
var newArray = [];
var result;
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:16
Diff two arrays
/*
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both.
In other words, return the symmetric difference of the two arrays.
*/
function diffArray(arr1, arr2) {
var newArr = [];
function check(first, second) {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:19
Roman Numeral Converter
/*
Convert the given number into a roman numeral.
All roman numerals answers should be provided in upper-case.
*/
function convertToRoman(num) {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:23
Wherefore art thou
/*
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have
matching property and value pairs (second argument). Each property and value pair of the source object has to be present
in the object from the collection if it is to be included in the returned array.
For example, if the first argument is [{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null },
{ first: "Tybalt", last: "Capulet" }], and the second argument is { last: "Capulet" },
then you must return the third object from the array (the first argument), because it contains the property and
its value, that was passed on as the second argument.
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:24
Search and Replace
/*
Perform a search and replace on the sentence using the arguments provided and return the new sentence.
First argument is the sentence to perform the search and replace on.
Second argument is the word that you will be replacing (before).
Third argument is what you will be replacing the second argument with (after).
NOTE: Preserve the case of the original word when you are replacing it. For example if you mean to replace the word
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:26
Pig Latin
/*
Translate the provided string to pig latin.
Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay".
If a word begins with a vowel you just add "way" to the end.
Input strings are guaranteed to be English words in all lowercase.
*/
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:28
DNA pairing
/*
The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
Return the provided character as the first element in each array.
For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]]
The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:30
Missing Letter
/*
Find the missing letter in the passed letter range and return it.
If all letters are present in the range, return undefined.
*/
function fearNotLetter(str) {
str = str.split('');
var alphabet = 'abcdefghijklmnopqrstuvwxyz';
alph = alphabet.split('');