Skip to content

Instantly share code, notes, and snippets.

Amen Moja Ra mojaray2k

Block or report user

Report or block mojaray2k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mojaray2k
mojaray2k / redux-examples.md
Last active Jun 12, 2019
Readux Esamples with patterns and middleware
View redux-examples.md

Redux Examples

Simple Redux Application

// state
let state = [];
// reducer
let reducer = (state, action) => {
  if(action.type === 'NEW_ORDER') {
    let newState = [...state, action.payload];
@mojaray2k
mojaray2k / cloudSettings
Created Jan 22, 2019
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2019-01-22T11:17:24.567Z","extensionVersion":"v3.2.4"}
View jsbin.diqumox.js
/** Rest and Spread Operators */
// Example #1 Rest Operator
function adddNumbers(...numbers) {
return numbers.reduce((sum, number) => {
return sum + number;
}, 0)
}
const totalNumbers = adddNumbers(1,2,3,4,5,6,7);
console.log(totalNumbers);
View jsbin.diqumox.js
/** Default Function Arguments */
// Example #1
function makeAjaxRequest(url, method = 'GET') {
return method;
}
console.log(makeAjaxRequest('google.com'));
// Example #2
function User(id) {
this.id = id;
View jsbin.diqumox.js
/* Enhanced Object Literals */
const inventory = [
{ title: 'Harry Potter', price: 10 },
{ title: 'Eloquent Javascript', price: 15 }
];
// Object Literals the ES5 way example #1
function createBookshopES5(inventory) {
return {
inventory: inventory,
View jsbin.diqumox.js
/* Fat Arrow Functions */
// arrow function example #1 - with implicit return
const add = (a, b) => a + b;
const sum = add(1,2)
console.log(sum);
// arrow function example #2 - if you only have one argument you don't need ()
const double = number => 2 * number;
const multiply = double(8);
console.log(multiply);
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
View jsbin.diqumox.js
// Count the number of vowels in a string using just var
function count(targetString){
var characters = ['a', 'e', 'i', 'o', 'u'];
var number = 0;
for (var i = 0; i< targetString.length; i++){
if(characters.includes(targetString[i])){
number++
}
}
return number;
@mojaray2k
mojaray2k / reduce-array-method-example-5.js
Last active Aug 23, 2018
The Reduce Array Method Example 5
View reduce-array-method-example-5.js
/**
* Reducing Properties
* Use the 'reduce' helper to create an object that tallies the number of sitting and standing desks.
* The object returned should have the form '{ sitting: 3, standing: 2 }'.
* The initial value has been provided to you.
* Hint: Don't forget to return the accumulator object (the first argument to the iterator function)
*/
var desks = [
{ type: 'sitting' },
You can’t perform that action at this time.