Last active
September 10, 2023 18:57
-
-
Save Constantiner/c2f3fa2db0ec4cc03b8b9faf19a9f4f4 to your computer and use it in GitHub Desktop.
Test description
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 getPairs = (arr, x) => arr.reduce(({pairs, subarray}, element) => ({pairs, | |
| subarray: (subarray.forEach(elem => pairs.push([element, elem])), subarray.slice(1))}), | |
| {pairs: [], subarray: arr.slice(1)}).pairs.filter(([a, b]) => a + b === x); | |
| const arr = [ 3, 4, 5, -2, 10, 11, 12, -1, 0, 7, 8 ], | |
| x = 10; | |
| console.log(getPairs(arr, x)); |
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 { P } from "@/components/ui/typography"; | |
| import { NotionBlockObjectResponse, isNotionCodeBlock } from "@/types/notion/block"; | |
| import { makePlainText } from "@/util/richTextUtil"; | |
| import { Code } from "bright"; | |
| import { FunctionComponent } from "react"; | |
| import { Caption } from "./util/caption"; | |
| import "./code.css"; | |
| export const CodeBlock: FunctionComponent<{ block: NotionBlockObjectResponse }> = ({ block }): JSX.Element | null => { | |
| if (isNotionCodeBlock(block)) { | |
| const code = makePlainText(block.code.rich_text); | |
| const language = block.code.language; | |
| return ( | |
| <section className="[&:not(:first-child)]:mt-4 md:[&:not(:first-child)]:mt-6"> | |
| <P className="kodama-code-block !m-0" asChild> | |
| <Code | |
| lang={language} | |
| theme={{ | |
| dark: "dracula", | |
| light: "github-light", | |
| lightSelector: "html.light" | |
| }} | |
| lineNumbers | |
| > | |
| {code} | |
| </Code> | |
| </P> | |
| <Caption caption={block.code.caption}></Caption> | |
| </section> | |
| ); | |
| } | |
| return null; | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sample solution with extra loop (filter) for a simple problem of finding pairs in array of integers which sum is equal to some integer value.