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 toObj = (key, value) => ({ [key]: value }) // toObj('hello', 'world) === { hello: 'world' } | |
const countOne = name => toObj(name, 1) // countOne('Tatooine') === { Tatooine: 1 } |
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 { compose, get } from 'conductor' | |
const getHomeworldName = compose(get('name'), fetchJSON, get('homeworld'), fetchCharacter) | |
// getHomeworldName(1) == { name: 'Tatooine', ... } |
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 character_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
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 fetchJSON = url => fetch(url).then(res => res.json()) | |
const fetchCharacter = id => fetchJSON(`https://swapi.co/api/people/${id}`) | |
// fetchCharacter(1) == { name: 'Luke Skywalker', homeworld: 'https://swapi.co/api/planets/1/' } |
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
{ | |
Alderaan: { | |
brown: 1 | |
}, | |
Naboo: { | |
red: 1 | |
}, | |
Stewjon: { | |
'blue-gray': 1, | |
Tatooine: { |
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 homeworld_stats = { Alderaan: 1, Naboo: 1, Stewjon: 1, Tatooine: 7 } |
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 { reduce } from 'conductor' | |
const obj = { books: 10, ruler: 1, pencils: 5 } | |
const add = (a, b) => a + b | |
const total = reduce(add, 0, obj) // 16 |
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 add = (a, b) => a + b | |
const total = Object.values(obj).reduce(add, 0) // 16 |
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 obj = { books: 10, ruler: 1, pencils: 5 } |
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 result = await Promise | |
.all(Object.values(obj).map(isEven)) | |
.then(results => Object.keys(obj).reduce((acc, key, index) => { | |
if (results[index]){ | |
acc[key] = obj[key] | |
} | |
return acc | |
}, {}) // { books: 10 } |