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 groupAnagrams(anagrams: string[]) { | |
const grouped: { [name: string]: string[] } = {}; | |
for(const anagram of anagrams) { | |
const sorted = anagram.split('').sort().join(''); | |
if(!grouped[sorted]) { | |
grouped[sorted] = [anagram]; | |
} else { | |
grouped[sorted].push(anagram); | |
} | |
} |
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 longestPrefix(strings: string[]) { | |
const { 0: first, [strings.length - 1]: last } = [...strings].sort(); | |
let prefixLength = -1; | |
for (let i = 0; i < Math.min(first.length, last.length); i++) { | |
if (first[i] === last[i]) { | |
prefixLength = i; | |
} else { | |
break; | |
} | |
} |
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 * as React from "react"; | |
import { render, RenderResult } from "@testing-library/react"; | |
import fetch from "jest-fetch-mock"; | |
import { useGetAnnotation } from "./useGetAnnotation"; | |
import { act } from "react-dom/test-utils"; | |
fetch.enableMocks(); | |
const presignedUrl = "https:/a-presigned-url"; | |
const testXml = btoa("<something/>"); |
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 React from "react"; | |
import { Tabs, ButtonGroup, Button } from "@emisgroup/ui-kit-react"; | |
const TabComponent = () => { | |
const tabsList = [{ text: "Tab1" }, { text: "Tab2" }, { text: "Tab3" }]; | |
const [selectedTab, setSelectedTab] = React.useState(0); | |
return ( | |
<> | |
<Tabs tabsList={tabsList} activeTab={selectedTab} onTabSelect={setSelectedTab} /> |
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 React from "react"; | |
import { Dropdown, Checkbox, RadioButtons, FormElement } from "@emisgroup/ui-kit-react"; | |
const testData = [ | |
{ | |
text: "Item one", | |
isChecked: false, | |
radioItem: "one", | |
}, | |
{ |
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 evenWord(word) { | |
let charCounts = [...word].reduce( | |
(charCount, char) => ({ | |
...charCount, | |
[char]: charCount[char] ? charCount[char] + 1 : 1, | |
}), | |
{}, | |
); | |
return Object.entries(charCounts).filter(([_, count]) => count % 2 !== 0).length; | |
} |
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 * as React from "react"; | |
const Forward = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => ( | |
<div ref={ref} style={{ width: "100%", height: "30px", backgroundColor: "green" }} /> | |
)); | |
function ForwardRef() { | |
const divRef = React.useRef<HTMLDivElement>(null); | |
React.useEffect(() => { |
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 * as React from "react"; | |
class CallbackRef extends React.Component { | |
divRef: HTMLDivElement | null = null; | |
setDivRef = (element: HTMLDivElement) => { | |
this.divRef = element; | |
}; | |
componentDidMount() { |
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 * as React from "react"; | |
class CreateRef extends React.Component { | |
divRef = React.createRef<HTMLDivElement>(); | |
componentDidMount() { | |
if (this.divRef.current) { | |
console.log(`createRefRef div width: ${this.divRef.current.clientWidth}`); | |
} | |
} |
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 * as React from "react"; | |
function HookRef() { | |
const divRef = React.useRef<HTMLDivElement>(null); | |
React.useEffect(() => { | |
if (divRef.current) { | |
console.log(`hookRef div width: ${divRef.current.clientWidth}`); | |
} | |
}, []); |