This file contains hidden or 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
using System; | |
using System.Linq; | |
using System.Web.Script.Serialization; | |
class Main { | |
public static void Main (string[] args) { | |
string username = "George"; | |
string[] orderedHeroes = { "Luke Skywalker", "Han Solo", "Leia Organa", "Rey", "Finn", "Poe Dameron" }; | |
// Store CreateRanking in a variable as a first-class function. |
This file contains hidden or 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 curriedCreateRanking = _.curry(createRanking); | |
const whatIsThis = curriedCreateRanking(currentUser); | |
console.log(orderedHeroes.map(whatIsThis)); | |
// Output: [ | |
// {'username':'George','rebel':'Luke Skywalker','index':0}, | |
// {'username':'George','rebel':'Han Solo','index':1}, | |
// {'username':'George','rebel':'Leia Organa','index':2}, | |
// {'username':'George','rebel':'Rey','index':3}, | |
// {'username':'George','rebel':'Finn','index':4}, |
This file contains hidden or 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 partialCreateRanking = _.partial(createRanking, currentUser); | |
console.log(orderedHeroes.map(partialCreateRanking)); | |
// Output: [ | |
// {'username':'George','rebel':'Luke Skywalker','index':0}, | |
// {'username':'George','rebel':'Han Solo','index':1}, | |
// {'username':'George','rebel':'Leia Organa','index':2}, | |
// {'username':'George','rebel':'Rey','index':3}, | |
// {'username':'George','rebel':'Finn','index':4}, | |
// {'username':'George','rebel':'Poe Dameron','index':5} |
This file contains hidden or 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 currentUser = 'George'; | |
const starWarsHeroes = [ | |
'Luke Skywalker', | |
'Han Solo', | |
'Leia Organa', | |
'Rey', | |
'Finn', | |
'Poe Dameron' | |
]; |
This file contains hidden or 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
// Use in place of `[]`. | |
const list1 = Immutable.List(['A', 'B', 'C']); | |
const list2 = list1.push('D', 'E'); | |
console.log([...list1]); // ['A', 'B', 'C'] | |
console.log([...list2]); // ['A', 'B', 'C', 'D', 'E'] | |
// Use in place of `new Map()` | |
const map1 = Immutable.Map([ |
This file contains hidden or 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 set = new Set(['A', 'B', 'C']); | |
// Instead of: set.add('D'); | |
const set2 = new Set([...set, 'D']); | |
// Instead of: set.delete('B'); | |
const set3 = new Set([...set].filter(key => key !== 'B')); | |
// Instead of: set.clear(); | |
const set4 = new Set(); |
This file contains hidden or 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 map = new Map([ | |
[1, 'one'], | |
[2, 'two'], | |
[3, 'three'] | |
]); | |
// Instead of: map.set(4, 'four'); | |
const map2 = new Map([...map, [4, 'four']]); | |
// Instead of: map.delete(1); |
This file contains hidden or 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
'use strict'; | |
const a = Object.freeze([4, 5, 6]); | |
// Instead of: a.push(7, 8, 9); | |
const b = a.concat(7, 8, 9); | |
// Instead of: a.pop(); | |
const c = a.slice(0, -1); |
This file contains hidden or 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 constants = { | |
heightRequirement: 46, | |
// ... other constants go here | |
}; | |
function canRide(height) { | |
return height >= constants.heightRequirement; | |
} |
This file contains hidden or 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 heightRequirement = 46; | |
function canRide(height) { | |
return height >= heightRequirement; | |
} |
NewerOlder