Skip to content

Instantly share code, notes, and snippets.

View andrit's full-sized avatar

Andrew Ritter andrit

View GitHub Profile
addCheckboxToSelectedArray = (item, hash) => {
    return new Promise((res, rej) => {
      try{
        let checkboxes = this.state.selectedCheckboxes;
        if(checkboxes.some(e => e.value === item)){
           const findIndexOf = function(arr, val){
             for(let i = 0; i < arr.length; i++) {
 if(arr[i]['value'] === val){
 checkForm = ({firstname, lastname, phone, email}) => {
        const phoneRegex = /^\(?\d{3}\D*\d{3}\D*\d{4}$/; 
            const emailRegex=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            let emailInvalid = false; 
            let phoneInvalid = false;
            if(!email.match(emailRegex) ){
                emailInvalid = true;
            }
    
let arr = [ 
                 {hash: "11223344", value: "abc"},
                 {hash: "11223344", value: "def"},
                 {hash: "22113344", value: "jkl"},
                 {hash: "22113344", value: "zyw"},
                 {hash: "33221144", value: "omn"},
                 {hash: "33221144", value: "xyz"}
 ];
let array = [ 
  {hash: "11223344", value: "abc"},
  {hash: "11223344", value: "def"},
  {hash: "22113344", value: "jkl"},
  {hash: "22113344", value: "zyw"},
  {hash: "33221144", value: "omn"},
  {hash: "33221144", value: "xyz"}
];
@andrit
andrit / reduceByIndexOfKey.md
Created September 24, 2018 15:18
and I wanted to loop through that array and create a new array whereby each each hash is only listed once and each value that was listed with a given is added to an array at the key value in the object of the single hash, like this:
let array = [{
    hash: "11223344",
    value: "abc"
  },
  {
    hash: "11223344",
    value: "def"
  },
 {
@andrit
andrit / reduceByIndexOfKey.md
Last active September 24, 2018 15:18
and I wanted to loop through that array and create a new array whereby each each hash is only listed once and each value that was listed with a given is added to an array at the key value in the object of the single hash, like this:
let array = [{
    hash: "11223344",
    value: "abc"
  },
  {
    hash: "11223344",
    value: "def"
  },
 {
@andrit
andrit / valueToArrayIfRepeatHash.md
Created September 21, 2018 16:27
takes a state array, like: 0: { hashKey: "5bdbeca67ac99d2e1389e154044585f8f8639bf5" value: "APPLE"} matches Hashes and puts values into array of values for each exclusive hash
 createApiCheckboxArray = (arr) => {
    /**
     * array.keys
     */
    arr.map((item, i) => {
      if(item.hashKey === i.hashKey){
        let valArr = [];
        valArr.concat(i.value);
 Object.assign({item.hashKey}, valArr)
@andrit
andrit / flattenObject.md
Created September 21, 2018 13:20
Flatten a multidimensional object to one dim
let flattenObject = function(ob) {
	let toReturn = {};
	
	for (var i in ob) {
		if (!ob.hasOwnProperty(i)) continue;
		
		if ((typeof ob[i]) == 'object') {
			let flatObject = flattenObject(ob[i]);
 for (let x in flatObject) {
@andrit
andrit / filterObjectBasedOnValue.md
Created September 18, 2018 13:44
filter out the object that has a match for the key value
var ob=[
  {name:'john', surname:'miller', role:'teacher'},
  {name:'jill',surname:'smith', role:'student'},
  {name:'jeff', surname:'summers', role:'student'},
  {name:'lisa',surname:'kenson', role:'teacher'}];

let input = 'teacher';

var res = ob.filter(o=&gt;Object.values(o).includes(input));
import React from 'react';
import Transition from 'react-transition-group/Transition';

const duration = 300;

const defaultStyle = {
  transition: `all ${duration}ms ease-in-out`,
  opacity: 0,
 top: 1000