Skip to content

Instantly share code, notes, and snippets.

View mojaray2k's full-sized avatar

Amen Moja Ra mojaray2k

  • Miami, Fl
View GitHub Profile
@mojaray2k
mojaray2k / react-toggle-button.md
Created May 5, 2020 22:38
Create A Toggle Button in a React Class

Create a Toggle Button in a React Class

import React from 'react';
import ReactDOM from 'react-dom';

class Toggle extends React.Component {
  constructor(props) {
    super(props);
 this.state= {

A Thunk filters actions to either return a function or an object

  const thunk = (store) => (next) => (action) => {
    if (typeof action === "function") {
      return action(store.dispatch);
    }

    return next(action);
  };
@mojaray2k
mojaray2k / async-await.md
Last active April 29, 2020 15:30
Using Async/Await

Here are some examples of using Async/Await

// function fetchAlbums(){
//   fetch('https://rallycoding.herokuapp.com/api/music_albums')
//     .then(res => res.json())
//     .then(json => console.log(json))
// }

// console.log(fetchAlbums());
@mojaray2k
mojaray2k / array.filter.md
Last active April 25, 2020 18:11
Using Array.filter Method

Array.filter()

  • The filter() method creates a new array with array elements that passes a test.
  • The filter() method takes a callback function which has 3 arguments:
    • The item value
    • The item index
    • The array itself

In this example I am you looking to simply remove all objects(items in the array) for which a category has already appeared once. You can do this with the Vanilla Javascript filter method. You simply have to use an object to keep count of whether the object has appeared before or not.

@mojaray2k
mojaray2k / array.sort.md
Last active April 24, 2020 14:33
Array Sort Method

Definition and Usage

TThe sort() method sorts the items of an array.

The sort order can be either alphabetic or numeric, and either ascending (up) or descending (down).

By default, the sort() method sorts the values as strings in alphabetical and ascending order.

This works well for strings ("Apple" comes before "Banana"). However, if numbers are sorted as strings, "25" is bigger than "100", because "2" is bigger than "1".

@mojaray2k
mojaray2k / array.concat.md
Last active April 24, 2020 05:52
Array Concat Method

Definition and Usage

The concat method is used to join two or more arrays. This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.

// join two arrays
var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var children = hege.concat(stale);
@mojaray2k
mojaray2k / array.constructor..md
Last active April 24, 2020 05:53
Array constructor Property

Definition and Usage

In JavaScript, the constructor property returns the constructor function for an object.

The return value is a reference to the function, not the name of the function:

For JavaScript arrays the constructor property returns function Array() { [native code] }

For JavaScript numbers the constructor property returns function Number() { [native code] }

@mojaray2k
mojaray2k / array.reduce.md
Last active April 24, 2020 05:53
Using Array Reduce

Definition and Usage

The reduce() method reduces the array to a single value.

The reduce() method executes a provided function for each value of the array (from left-to-right).

The return value of the function is stored in an accumulator (result/total).

Note: reduce() does not execute the function for array elements without values.

@mojaray2k
mojaray2k / colorize-mac-terminal.md
Last active April 9, 2020 04:43
Colorize You Mac or Linux Terminal

How To Customize Your Terminal

  1. Create a .bash_profile in your ~/ home directory on your mac or linux machine.
  2. Copy the following snippet of code into your .bash_profile.
# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
# Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
# A big thanks to \amethyst on Freenode
@mojaray2k
mojaray2k / redux-examples.md
Last active June 12, 2019 14:17
Readux Esamples with patterns and middleware

Redux Examples

Simple Redux Application

// state
let state = [];
// reducer
let reducer = (state, action) => {
  if(action.type === 'NEW_ORDER') {
    let newState = [...state, action.payload];