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 quicksort(list) { | |
| if (list.length < 2) { | |
| return list | |
| } else { | |
| let pivot = list[0] | |
| let restOfList = list.slice(1) | |
| let listGreaterThanPivot = [] | |
| let listSmallerThanPivot = [] | |
| for (let i = 0; i < restOfList.length; i++) { |
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
| // Calculate factorial via recursion | |
| const calculateFactorial = (num) => { | |
| if (num === 1) { | |
| return 1 | |
| } else { | |
| return num * calculateFactorial(num - 1) | |
| } | |
| } | |
| // console.log('3', calculateFactorial(3)) |
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
| // Selection Sort | |
| const sort = (arr) => { | |
| let list = arr | |
| const findSmallestValue = () => { | |
| let smallest = list[0] | |
| let smallestIndex = 0 | |
| for (let i = 1; i < list.length; i++) { | |
| if (list[i] < smallest) { |
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
| // Binary search | |
| const bSearch = (list, number) => { | |
| // low and high keep track of which part of the list you’ll search in. | |
| let low = 0 | |
| let high = list.length - 1 | |
| // While you haven’t narrowed it down to one element … | |
| while (low <= high) { | |
| let mid = Math.floor((low + high) / 2) | |
| // … check the middle element. |
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 find_max(nums) { | |
| let max_num = Number.NEGATIVE_INFINITY; // smaller than all other numbers | |
| for (let num of nums) { | |
| if (num > max_num) { | |
| max_num = num | |
| } | |
| } | |
| return max_num; | |
| } |
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 path = require("path"); | |
| const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
| module.exports = { | |
| entry: "./src/index.tsx", | |
| output: { | |
| path: path.resolve(__dirname, "dist"), | |
| filename: "bundle.js", | |
| }, | |
| resolve: { |
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 NON_SPECIAL_CHARS_REGEX = /\W+|[_]+/; | |
| const WHITE_SPACE_REGEX = /\s+/; | |
| const formatCamelCase = (text) => { | |
| const formatCase = (word, index) => { | |
| const formattedNonFirstWord = word.charAt(0).toUpperCase() + word.slice(1); | |
| return index === 0 ? word.toLowerCase() : formattedNonFirstWord | |
| }; | |
| return text | |
| .replace(NON_SPECIAL_CHARS_REGEX, ' ') |
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 FIRST_PARAGRAPH_TAG_REGEX = /<p>(.*?)<\/p>/; | |
| const INLINE_STYLE_REGEX = /style="[^"]*"/g; |
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 VIDEO_FILE_REGEX = /video\/\w+/gm; | |
| const AUDIO_FILE_REGEX = /audio\/\w+/gm; | |
| const IMAGE_FILE_REGEX = /image\/\w+/gm; |
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 { useEffect } from 'react'; | |
| import { KeyboardKey } from 'enums/keyboardKey'; | |
| export const useKeyPress = (callback: (T?: any) => void, keys: KeyboardKey[]) => { | |
| const onKeyDown = (event: KeyboardEvent) => { | |
| const wasAnyKeyPressed = keys.some((key) => event.key === key); | |
| if (wasAnyKeyPressed) { | |
| event.preventDefault(); | |
| callback(); |
NewerOlder