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
export const getNUmberSuffix = (number: number): string => { | |
const thExceptions = (number: number) => | |
[11, 12, 13].some((exception) => exception === number); | |
const lastDigit = number % 10; | |
if (thExceptions(number) || lastDigit === 0 || lastDigit > 3) | |
return `${number}th`; | |
if (lastDigit === 1) return `${number}st`; | |
if (lastDigit === 2) return `${number}nd`; | |
return `${number}rd`; |
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
// This function takes a Generic of FoodType | |
function makeABunchOf<FoodType>(food: FoodType, howMany: number): FoodType[] { | |
const foodArray = Array.from({ length: howMany }, () => food); | |
return foodArray; | |
} | |
// Make our Food Types | |
interface Pizza { name: string; slices: number; } | |
interface Sandwich { name: string; veggie: boolean; } | |
// Make some Food |
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 { useState, useEffect } from "react"; | |
/* H/T: | |
Avoiding Race Conditions and Memory Leaks in React useEffect | |
https://javascript.plainenglish.io/avoiding-race-conditions-and-memory-leaks-in-react-useeffect-2034b8a0a3c7 | |
*/ | |
interface IUseFetchWithAbortResponse { | |
fetchedData: unknown; | |
isLoading: boolean; |
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
src/serviceWorker.ts |
OlderNewer