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
| type FieldPosition = 'GOALIE'|'STRIKER'|'MIDFIELD'|'DEFENDER' | |
| interface PlayerConfig { | |
| name: string; | |
| age: number; | |
| jerseyNumber?: (number | string) | |
| } | |
| //ERROR!! | |
| const player1: PlayerConfig = { | |
| name: "Jason", |
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
| enum FieldPosition {GOALIE, STRIKER, MIDFIELD, DEFENDER}; | |
| //pre-declared types | |
| const player: { | |
| name: 'Bob'; | |
| age: 24; | |
| hobbies: string[]; | |
| //tuple | |
| team: [string, number]; | |
| position: number; | |
| active: any; |
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
| // pre-declared types | |
| const person: { | |
| name: string; | |
| age: number; | |
| hobbies: string[]; | |
| } = { | |
| name: 'Bob', | |
| age: 24, | |
| hobbies: ['books', 'music'], | |
| } |
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 numButton = document.querySelector(".add-numbers")! as HTMLButtonElement; | |
| const strButton = document.querySelector(".add-with-string")! as HTMLButtonElement; | |
| const num1Input = document.querySelector(".num1-input")! as HTMLInputElement; | |
| const num2Input = document.querySelector(".num2-input")! as HTMLInputElement; | |
| const strInput = document.querySelector(".string-input")! as HTMLInputElement; | |
| function add( | |
| thing1: number, | |
| thing2: number, | |
| phrase: string, |
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 numButton = document.querySelector(".add-numbers")! as HTMLButtonElement; | |
| const strButton = document.querySelector(".add-with-string")! as HTMLButtonElement; | |
| const num1Input = document.querySelector(".num1-input")! as HTMLInputElement; | |
| const num2Input = document.querySelector(".num2-input")! as HTMLInputElement; | |
| const strInput = document.querySelector(".string-input")! as HTMLInputElement; | |
| const answer = document.querySelector(".answer")! as HTMLSpanElement; | |
| function add( | |
| thing1: number, | |
| thing2: number, |
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
| //WITHOUT TYPING | |
| const numButton = document.querySelector(".add-numbers"); | |
| const strButton = document.querySelector(".add-with-string"); | |
| const num1Input = document.querySelector(".num1-input"); | |
| const num2Input = document.querySelector(".num2-input"); | |
| const strInput = document.querySelector(".string-input"); | |
| function add(thing1, thing2, phrase, showString){ | |
| return showString ? phrase + (thing1 + thing2) : thing1 + thing2 |
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
| # ASSUMES ARRAYS ARE SORTED | |
| def merge(arr1, arr2) | |
| sorted_array = [] | |
| first_pointer = 0 | |
| second_pointer = 0 | |
| while(first_pointer < arr1.size && second_pointer < arr2.size) | |
| if(arr2[second_pointer] >= arr1[first_pointer]) | |
| sorted_array.push(arr1[first_pointer]) | |
| first_pointer += 1 |
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 radixSort = (nums) => { | |
| //get the max digits for the list | |
| let maxDigits = mostDigits(nums); | |
| //iterate from 0 to number of max digits | |
| //digit iterator | |
| for(let i = 0; i < maxDigits; i++){ | |
| // make digit buckets by crafting an array with 10 arrays inside it | |
| let digitBuckets = Array.from({length:10}, () => [])// same as const digitBuckets = [[],[],[],[],[],[],[],[],[],[]] | |
| //iterate over our numbers and place them into the proper bucket using helper functions |
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
| //get the digit in requested place (working backwards i.e. ones place is the last digit, tens is the second to last and so on) | |
| const getDigit = (num, place) => { | |
| //move the decimal point over to the requested digit (absolute value to consider negative numbers) | |
| const divided = Math.abs(num) / Math.pow(10, place); | |
| //round down to eliminate digits after the decimal | |
| const floored = Math.floor(divided); | |
| //modulo to get remainder when number is divided by it's base (10) | |
| const digit = floored % 10; |
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
| //creating default arguments again since we want to be able to change them in later recursions | |
| const quickSort = (arr, left = 0, right = arr.length - 1) => { | |
| //if the array has more than 1 item | |
| if(left < right){ | |
| //get the pivot index | |
| let pivotIndex = pivot(arr, left, right); | |
| //pass in the sort for the left side of the pivot | |
| quickSort(arr, left, pivotIndex - 1); | |
| //pass in the sort for the right side of the pivot | |
| quickSort(arr, pivotIndex + 1, right); |