เราจะมารู้เรื่อง Category
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
// Usage: | |
import isEven from "is-not-odd"; | |
isEven(3); // false | |
isEven(4); // true | |
// In index.ts of `is-not-odd` module | |
import isOdd from "is-odd"; | |
type PredicateFn<T> = (...args: [T, ...any[]]) => boolean; |
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 { compose, isEmpty, map } from 'lodash/fp'; | |
import { useQuery } from '@tanstack/react-query'; | |
// USAGE | |
// This makes us read "mapStrapiResponse toStaticContent AFTER fetchSomeStaticPageContent" | |
const fetchAndMapContent: () => Promise<SomeStaticContentAttrs> = compose( | |
mapStrapiResponse(toStaticContent), | |
fetchSomeStaticPageContent, | |
); | |
const pageContent: SomeStaticContentAttrs = await fetchAndMapContent(); |
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
// MSS - Maximum Sum Segment problem | |
// MSS = maximum . map sum . concat . map inits . tails | |
// Playground - https://tsplay.dev/mpzE6w | |
function tail<T>(xs: T[]): T[] { | |
return xs.slice(1) | |
} | |
function init<T>(xs: T[]): T[] { | |
return xs.slice(0, -1) | |
} |
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 type UnaryFn<T, R> = (arg: T) => R; | |
export function compose<R>(fn: UnaryFn<any, R>): UnaryFn<any, R>; | |
export function compose<T1, R>(fn1: UnaryFn<T1, R>): UnaryFn<T1, R>; | |
export function compose<T1, T2, R>( | |
fn2: UnaryFn<T2, R>, | |
fn1: UnaryFn<T1, T2> | |
): UnaryFn<T1, R>; | |
export function compose<T1, T2, T3, R>( | |
fn3: UnaryFn<T3, R>, |
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 IconFacebook from '../components/icons/IconFacebook' | |
import IconTwitter from '../components/icons/IconTwitter' | |
function YourPage() { | |
const [hoveredIcons, setHoveredIcons] = useState({ | |
fb: false, | |
tw: false, | |
ig: false, | |
pt: false, | |
}) |
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
function IconFacebook({ fill = "#FFF", width = 24, height = 24 }) { | |
return ( | |
<svg xmlns="http://www.w3.org/2000/svg" width={width} height={height}> | |
<path | |
fill={fill} | |
d="M22.675 0H1.325C.593 0 0 .593 0 1.325v21.351C0 23.407.593 24 1.325 24H12.82v-9.294H9.692v-3.622h3.128V8.413c0-3.1 1.893-4.788 4.659-4.788 1.325 0 2.463.099 2.795.143v3.24l-1.918.001c-1.504 0-1.795.715-1.795 1.763v2.313h3.587l-.467 3.622h-3.12V24h6.116c.73 0 1.323-.593 1.323-1.325V1.325C24 .593 23.407 0 22.675 0z" | |
/> | |
</svg> | |
) | |
} |
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
function cp(start = 0, end = 10) { | |
const spanParagraphs = document.querySelectorAll('[class^=transcript--underline-cue] > span') | |
const texts = Array.from(spanParagraphs) | |
.slice(start, end) | |
.map(mapInnerText) | |
.reduce(concat, []) | |
const result = texts.join(' ').replaceAll('. ', '.\n') |
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
function zip(xs, ys) { | |
if (xs.length < ys.length) { | |
return xs.map((x, idx) => [x, ys[idx]]) | |
} else { | |
return ys.map((y, idx) => [xs[idx], y]) | |
} | |
} | |
// FP Style |
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
// Udemy | |
function cp() { | |
copy(document.querySelector('span[class^=well--text]').innerText + ' ') | |
} | |
function playPause() { | |
document.querySelector('.vjs-tech').click() | |
} | |
function cp() { |
NewerOlder