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 nestedData = [1, 2, [3, [4, 5]]] | |
const flatten = (arr) => { | |
return arr.reduce((acc, cur) => { | |
return acc.concat(Array.isArray(cur) ? flatten(cur) : cur) | |
}, []) | |
} | |
const result = flatten(nestedData) |
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 categories = [ | |
{ id: 1, label: "Action" }, | |
{ id: 2, label: "Romance" }, | |
{ id: 3, label: "Comedy" }, | |
{ id: 4, label: "Horror" }, | |
] | |
const result = categories.reduce((acc, cur) => { | |
const { id, label } = cur | |
acc[id] = label |
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 data = [ | |
{ name: "Chanon", age: 28, voted: true }, | |
{ name: "Tim", age: 20, voted: true }, | |
{ name: "Sarah", age: 27, voted: true }, | |
{ name: "Jeff", age: 17, voted: false }, | |
] | |
const result = data.reduce((acc, cur) => { | |
return { | |
maxAge: Math.max(acc.maxAge, cur.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
const data = [ | |
{ name: "Chanon", age: 28, voted: true }, | |
{ name: "Tim", age: 20, voted: true }, | |
{ name: "Sarah", age: 27, voted: true }, | |
{ name: "Jeff", age: 17, voted: false }, | |
] | |
const result = data.reduce((acc, cur) => { | |
return { | |
totalVotes: acc.totalVotes + (cur.voted ? 1 : 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 data = [1, 2, 3] | |
const result = data.reduce((acc, cur) => { | |
return acc + cur | |
}, 0) | |
// result: 6 |
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 React, { Component } from "react" | |
import { | |
ScrollView, | |
Animated, | |
SafeAreaView, | |
ImageBackground, | |
Dimensions, | |
} from "react-native" | |
const OFFSET = 40 |
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 React, { Component } from "react" | |
import { | |
View, | |
ScrollView, | |
SafeAreaView, | |
ImageBackground, | |
Dimensions, | |
} from "react-native" | |
const ITEM_WIDTH = Dimensions.get("window").width |
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 { debounce } from 'lodash' | |
import { track } from './analytics-service' | |
export default function App() { | |
const [value, setValue] = useState("") | |
const trackAnalytics = (val) => { | |
if (val) track(val) | |
} | |
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 { debounce } from 'lodash' | |
import { track } from './analytics-service' | |
export default function App() { | |
const [value, setValue] = useState("") | |
const trackAnalytics = (val) => { | |
if (val) track(val) | |
} | |
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
export const waitFor = async (cb: any) => { | |
let c = 0 | |
async function f() { | |
try { | |
await cb() | |
} catch (error) { | |
if (c < 9) { | |
c += 1 | |
setTimeout(f, 500) |
NewerOlder