Skip to content

Instantly share code, notes, and snippets.

import { AUTH_USER, AUTH_ERROR } from "../actions/types";
export default function(state = {}, action) {
switch (action.type) {
case AUTH_USER:
return { ...state, error: "", authenticated: true };
case AUTH_ERROR:
return { ...state, error: action.payload.response };
}
@Tinusw
Tinusw / index.js
Created April 19, 2018 10:43
actions/index.js
import axios from "axios";
import { AUTH_USER, AUTH_ERROR } from "./types";
const ROOT_URL = "http://localhost:";
const PORT = "3030";
export function signinUser({ email, password }) {
return ((dispatch) => {
return axios.post(`${ROOT_URL}${PORT}/signin`, { email, password })
users = [
{id: 1, firstname: 'steven', lastname: 'jones',
comments: [
{id: 1, post_id: 1, comment: 'woah cool bro'}
]},
{id: 2, firstname: 'don', lastname: 'king',
comments: [
{id: 3, post_id: 1, comment: 'dope'}
]
},
@Tinusw
Tinusw / weight_results.js
Last active March 28, 2018 13:48
Reverse Index Lookup to Weight Scores
let search_term = 'bla'
let results = [
{id: 1, desc: "b", topic: "bla", name: "b", match: 0.33},
{id: 2, desc: "b", topic: "b", name: "bla", match: 0.33},
{id: 3, desc: "bla", topic: "b", name: "b", match: 0.33}
]
let lookup_table = [
{ attribute: 'name', weight: 0.3 },
@Tinusw
Tinusw / 4.js
Last active March 28, 2018 13:41
sortResults = (arr) => {
return arr.sort((a, b) => b.match - a.match)
}
calculateNewMatch = (object, weighting) => {
return object.match * weighting
}
@Tinusw
Tinusw / 2.js
Last active March 28, 2018 13:38
returnWeightedLookupByKey = (lookup_table, attribute) => {
return lookup_table.find(x => x.attribute === attribute).weight
}
findKeyBySearchTerm = (object, term) => {
return Object.keys(object).find(key => object[key] === term);
}
console.log(1 < 2 < 3);
console.log(3 > 2 > 1);
function sum(arg1) {
if (arguments.length > 1) {
return arguments[0] + arguments[1];
} else {
return function(arg2) {
return arg1 + arg2;
};
}
}