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 / cloudSettings
Created January 22, 2019 11:21
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-01-22T11:17:24.567Z","extensionVersion":"v3.2.4"}
/** 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);
/** 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;
/* 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,
/* 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);
<!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">
<!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">
// 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 April 2, 2023 14:41
The Reduce Array Method Example 5
/**
* 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' },
@mojaray2k
mojaray2k / reduce-array-method-example-4.js
Last active August 23, 2018 17:47
The Reduce Array Method Example 4
/**
* Distance Traveled
* Use the 'reduce' helper to find the sum of all the distances traveled.
* Assign the result to the variable 'totalDistance'
*/
const trips = [{ distance: 34 }, { distance: 12 } , { distance: 1 }];
const totalDistance = trips.reduce((total, trip) => {
total += trip.distance