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 snakeToCamel = (s: string): string => s.toLowerCase().replace(/(_\w)/g, (w) => w.toUpperCase().substring(1)); | |
| snakeToCamel('foo_bar'); // -> fooBar |
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 shuffleArray = <T>(arr: T[]): T[] => arr.sort(() => Math.random() - 0.5); | |
| shuffleArray(<number[]>[1, 2, 3, 4, 5]); // -> [ 4, 5, 2, 1, 3 ] |
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 slugify = (str: string): string => str.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, ''); | |
| slugify('Hello World'); // -> hello-world |
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
| <details> | |
| <summary>Epcot Center</summary> | |
| <p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions, international pavilions, award-winning fireworks and seasonal special events.</p> | |
| </details> |
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
| function isDenseArray(array) { | |
| for (let index = 0; index < array.length; index++) { | |
| if (!(index in array)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
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
| if (process.env.NODE_ENV === "production") { | |
| module.exports = require("./keys_prod"); | |
| } else { | |
| module.exports = require("./keys_dev"); | |
| } |
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 UI = { | |
| searchFail(failure) { | |
| if (failure === "query") { | |
| this.showAlert("Please enter a search query", "danger"); | |
| this.resetPage(); | |
| this.clearElement(".alert"); | |
| } else if (failure === "results") { | |
| this.showAlert("No books found", "danger"); | |
| this.resetPage(); | |
| this.clearElement(".alert"); |
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
| interface Foo { | |
| bar: number; | |
| baz: string; | |
| qux: Date; | |
| } | |
| type FooKey keyof Foo; // "bar" | "baz" | "qux" | |
| const fooLookUp = (key: FooKey) => foo[key] |
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
| ReactDOM.render( | |
| <Provider3> | |
| <Provider2> | |
| <Provider1> | |
| <App /> | |
| </Provider1> | |
| </Provider2> | |
| </Provider3>, | |
| rootElement | |
| ); |
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
| import React from "react"; | |
| const UserContext = React.createContext(); | |
| function UserProvider({ children }) { | |
| const user = { name: "Reed" }; | |
| return <UserContext.Provider value={user}>{children}</UserContext.Provider>; | |
| } | |
| function useUser() { |