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 getData = () => | |
| new Promise((resolve) => | |
| setTimeout(() => resolve(Math.random() * 5), Math.random() * 2000) | |
| ); | |
| const fetchThrottledData = () => { | |
| const arrOfData = []; | |
| let startTime = new Date().getTime(); | |
| const res = () => { |
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 firstUniqChar = (s) => { | |
| let res = new Map(); | |
| [...s].forEach((i) => { | |
| res.has(i) ? res.set(i, res.get(i) + 1) : res.set(i, 1) | |
| }) | |
| for (const [key, value] of res.entries()) { | |
| if(value === 1) { | |
| return s.indexOf(key) |
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
| // We have an array of strings stored in strArr, which will contain only two strings, | |
| // the first parameter being the string N and the second parameter being a string K of some characters. | |
| // Your goal is to determine the smallest substring of N that contains all the characters in K. | |
| // For example: if strArr is ["aabdccdbcacd", "aad"] then the smallest substring of N that contains | |
| // all of the characters in K is "aabd" which is located at the beginning of the string. | |
| // Both parameters will be strings ranging in length from 1 to 50 characters and | |
| // all of K's characters will exist somewhere in the string N. Both strings will only | |
| // contain lowercase alphabetic characters. | |
| // Examples |
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
| /** | |
| * @param {string} s | |
| * @param {string} t | |
| * @return {string} | |
| */ | |
| var minWindow = function(s, t) { | |
| let map = new Map(); | |
| let sLen = s.length; | |
| let tLen = t.length; |
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
| function TreeNode(val) { | |
| this.val = val; | |
| this.left = this.right = null; | |
| } | |
| /** | |
| * @param {TreeNode} root | |
| * @return {number} | |
| */ | |
| const maxDepth = root => { |
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
| mocha.setup('bdd'); | |
| var expect = chai.expect; | |
| const employees = [ | |
| { name: "Barak Obama", role: "president", pay: 35000 }, | |
| { name: "Noa Kirel", role: "artist", pay: 1000000 }, | |
| { name: "Donald Trump", role: "president", pay: 40000 }, | |
| { name: "Tova Cohen", role: "teacher", pay: 135210 }, | |
| { name: "Ivri Lider", role: "artist", pay: 32000 }, |
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
| class CustomPromise { | |
| state = "PENDING" | |
| value = undefined | |
| thenCallbacks = [] | |
| errorCallbacks = [] | |
| constructor(action) { | |
| action(this.resolver.bind(this), this.reject.bind(this)) | |
| } |
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 Icon: React.FC<IconProps> = ({ | |
| name, | |
| ...rest | |
| }): JSX.Element | null => { | |
| const ImportedIconRef = React.useRef< | |
| React.FC<React.SVGProps<SVGSVGElement>> | |
| >(); | |
| const [loading, setLoading] = React.useState(false); | |
| React.useEffect((): void => { |
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 paths = ["path/to/file1.doc", "path/to/file2.doc", "foo/bar.doc"]; | |
| const stringToTree = (data) => { | |
| return data.reduce((r, path) => { | |
| path.split('/').reduce((o, name) => { | |
| var temp = (o.children = o.children || []).find(q => q.name === name); | |
| if (!temp) o.children.push(temp = { name }); | |
| return temp; | |
| }, r); |
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 data = [ | |
| { | |
| "name": "path", | |
| "children": [ | |
| { | |
| "name": "to", | |
| "children": [ | |
| { | |
| "name": "file1", | |
| "value": true, |