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
// before method simplification | |
function parseAndSanitizeAndGenerateDocument(data) { | |
const parsedData = []; | |
for (let index = 0; index < data.length; index++) { | |
const element = data[index]; | |
if (element.name === 'bacon') { | |
parsedData.push({ | |
name: element.name, | |
age: element.age, | |
}); |
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
// before - 5 args too many | |
function initializeNewUserWorflow( | |
email, password, location, | |
organization, referred) { | |
// initialize the new user | |
} | |
// after - using configuration object | |
const initializeUserConfiguration = { | |
email: 'email', |
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
import datetime | |
from github import Github | |
g = Github('token') | |
me = g.get_user() | |
repos = me.get_repos() | |
def is_a_repo_contributor(repo): | |
contributors = repo.get_contributors() | |
return me.id in map(lambda con: con.id, contributors) |
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
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ]; | |
// improved looping | |
fruits.forEach((value, index, array) => { | |
console.log('fruit at index', index, '=', value); | |
}); | |
// what you may already be used to | |
for (let i=0; i<fruits.length; i++) { | |
console.log('fruit at index', i, '=', fruits[i]); |
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
const fruits = ['pineapple', 'apple', 'banana','pear']; | |
const aFruit = fruits.find((element) => { | |
return element.includes('apple'); | |
}); | |
let aFruit; | |
for (let i = 0; i < fruits.length; i++) { | |
if (fruits[i].includes('apple')) { |
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
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ]; | |
const matchedFruits = fruits.filter((element) => { | |
return element.includes('apple'); | |
}); | |
let matchedFruitsAgain = []; | |
for (let i = 0; i < fruits.length; i++) { | |
if (fruits[i].includes('apple')) { |
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
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ]; | |
console.log('map() example'); | |
const upperCaseFruits = fruits.map((value) => { | |
return value.toUpperCase(); | |
}); | |
console.log('upperCaseFruits =', upperCaseFruits, '\n'); | |
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
const animals = [ | |
{animal: 'zebra', count: 4}, {animal: 'tiger', count: 2}, | |
{animal: 'lion', count: 3}, {animal: 'turtle', count: 9}, | |
{animal: 'pig', count: 2}, | |
]; | |
console.log('reduce() example'); | |
const count = animals.reduce((total, curr) => { | |
return total += curr.count; | |
}, 0); |
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
const year = 2019; | |
const month = 10; // november, zero-indexed | |
const startDay = 14; | |
console.log('Array.from() example'); | |
const dateList = Array.from({length:7}, (val, idx) => { | |
return new Date(year, month, startDay + idx); | |
}); | |
console.log('dateList = ', dateList, '\n'); |
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
const taxPayer = [ 'Ian', 'DesJardins', '123-45-6789', true ]; | |
console.log('Array destructuring example'); | |
// destructure the taxPayer array into new variables | |
const [ firstName, lastName, ssn, pastDue ] = taxPayer; | |
console.log('firstName =', firstName); | |
console.log('lastName =', lastName); | |
console.log('ssn =', ssn); | |
console.log('pastDue =', pastDue, '\n'); |