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 persons = [ | |
| { firstName: "Alice", lastName: "Smith", age: 30, cars: [{ brand: "Ford", model: "Fiesta", licensePlateNumber: "ABC123" }] }, | |
| { firstName: "Bob", lastName: "Johnson", age: 25, cars: [{ brand: "Toyota", model: "Corolla", licensePlateNumber: "DEF456" }, { brand: "Honda", model: "Civic", licensePlateNumber: "GHI789" }] }, | |
| { firstName: "Eve", lastName: "Jones", age: 35, cars: [] } | |
| ]; | |
| const sortedByLastName = sortPersons(persons, "lastName"); | |
| console.log(sortedByLastName); | |
| const sortedByNumCars = sortPersons(persons, "numCars"); |
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 sortPersons(persons: Person[], sortKey: "lastName" | "numCars"): Person[] { | |
| return persons.sort((a, b) => { | |
| if (sortKey === "lastName") { | |
| return a.lastName.localeCompare(b.lastName); | |
| } else if (sortKey === "numCars") { | |
| return a.cars.length - b.cars.length; | |
| } | |
| }); | |
| } |
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
| //Hook | |
| function useMousePosition() { | |
| const mousePosition = React.useRef({ x: 0, y: 0 }) | |
| React.useEffect(() => { | |
| const updateMousePosition = (ev) => { | |
| mousePosition.current = { x: ev.clientX, y: ev.clientY } | |
| } | |
| window.addEventListener("mousemove", updateMousePosition) |
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 HEIGHT_LIMIT = 100 | |
| function Animated() { | |
| const divRef = React.useRef() | |
| const requestRef = React.useRef() | |
| const heightRef = React.useRef(0) | |
| const animate = () => { | |
| heightRef.current += 1 | |
| divRef.current.style.height = `${heightRef.current}px` |
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 TIMEOUT_LIMIT = 5000 | |
| function Notice() { | |
| const [isVisible, setIsVisible] = React.useState(true) | |
| const timeoutRef = React.useRef(null) | |
| const hideNotice = () => { | |
| setIsVisible(false) | |
| } |
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 NormalUsage() { | |
| const inputRef = React.useRef(); | |
| const handleSubmit = (e) => { | |
| e.preventDefault(); | |
| console.log(inputRef.current.value); | |
| }; | |
| return ( | |
| <form onSubmit={handleSubmit}> |
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
| <?php | |
| function remove_galleries( $content ) { | |
| $doc= new DOMDocument(); | |
| libxml_use_internal_errors(true); | |
| $doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8")); | |
| libxml_clear_errors(); | |
| $xpath = new DOMXpath($doc); | |
| $nodes = $xpath->query( "//div[contains(concat(' ', @class, ' '), ' gallery ')]"); | |
| foreach( $nodes as $node) { | |
| $node->parentNode->removeChild( $node); |