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 handleUpdate = async (user, onUpdated) => { | |
try { | |
await updateUser(user) | |
await updateProfile(user.profile) | |
await onUpdated(user) // email or notify something | |
} catch (e) { | |
// handling error | |
} | |
} |
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 tmp = new Set(); | |
const filtered = lists.filter(a => !tmp.has(a.code) && tmp.add(a.code)) |
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 filtered = uniqueByCode(lists) |
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 person = { score: 25 }; | |
let newScore = person.score | |
newScore = newScore + newScore | |
newScore += 7 | |
newScore = Math.max(0, Math.min(100, newScore)); | |
console.log(newScore) // 57 |
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
let newScore = person.score | |
newScore = double(newScore) | |
newScore = add(newScore, 7) | |
newScore = boundScore(0, 100, newScore) | |
console.log(newScore) // 57 |
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 person = { score: 25 }; | |
const newScore = person.score | |
|> double | |
|> add(7, ?) | |
|> boundScore(0, 100, ?); | |
newScore //=> 57 |
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 generateQuery = (params) => { | |
const query = {} | |
try { | |
if (params.email) { | |
const isValid = isValidEmail(params.email) | |
if (isValid) { | |
query.email = params.email | |
} | |
} |
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 email = (query, params) => { | |
if (!params.email) return query | |
const isValid = isValidEmail(params.email) | |
if (!isValid) throw new Error('Invalid email') | |
return { ...query, ...{ email: params.email } } | |
} | |
const maxAge = (query, params) => { |
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 generateQuery = (params, callbacks) => { | |
let query = {} | |
try { | |
callbacks.forEach(c => { | |
query = c(query, params) | |
}) | |
} catch(err) { | |
// error handing | |
} |
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 fetch = async () => { | |
return await axios.get('/users') | |
} | |
const users = await fetch() | |
... |