This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2019-01-22T11:17:24.567Z","extensionVersion":"v3.2.4"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |