Skip to content

Instantly share code, notes, and snippets.

@Constantiner
Last active September 10, 2023 18:57
Show Gist options
  • Select an option

  • Save Constantiner/c2f3fa2db0ec4cc03b8b9faf19a9f4f4 to your computer and use it in GitHub Desktop.

Select an option

Save Constantiner/c2f3fa2db0ec4cc03b8b9faf19a9f4f4 to your computer and use it in GitHub Desktop.
Test description
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));
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;
};
@Constantiner
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment