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
interface GenericInterface<U> { | |
value: U | |
getIdentity: () => U | |
} | |
class IdentityClass<T> implements GenericInterface<T> { | |
value: T | |
constructor(value: T) { | |
this.value = value |
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 Car { | |
label: string = 'Generic Car' | |
numWheels: Number = 4 | |
horn() { | |
return "beep beep!" | |
} | |
} | |
class Truck extends Car { | |
label = 'Truck' |
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 identity <T>(value: T) : T { | |
return value; | |
} | |
console.log(identity<Number>(1)) // 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
function identity (value: Number) : Number { | |
return value; | |
} | |
console.log(identity(1)) // 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
function identity (value) { | |
return value; | |
} | |
console.log(identity(1)) // 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
function identity (value) { | |
return value; | |
} | |
console.log(identity(1)) // 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 checkLoopInvariant = (newArray, originalArray, index) => { | |
newArray = newArray.slice(0, index) | |
originalArray = originalArray.sort((a,b) => a > b ? 1 : - 1).slice(0,index) | |
if (index === 0) return true //no elements sorted yet | |
for (let i = 0; i < newArray.length; i++) { | |
if (!originalArray.includes(newArray[i])) { | |
console.warn(`Error! ${newArray[i]} not one of the ${index} smallest elements`) | |
} |
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 selectionSort = (nums) => { | |
for (let i = 0; i < nums.length - 1; i++) { | |
let smallest = nums[i] | |
let swapIndex = i | |
for (let j = i + 1; j < nums.length; j++) { | |
if (nums[j] < smallest) { | |
smallest = nums[j]; | |
swapIndex = j | |
} | |
} |
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 insertionSort = (nums) => { | |
for (let i = 1; i < nums.length; i++) { | |
let j = i - 1 | |
let tmp = nums[i] | |
while (j >= 0 && nums[j] > tmp) { | |
nums[j + 1] = nums[j] | |
j-- | |
} | |
nums[j+1] = tmp | |
} |
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 checkLoopInvariant = (newArr, originalArr, index) => { | |
//need to slice at least 1 element out | |
if (index < 1) index = 1 | |
newArr = newArr.slice(0,index) | |
originalArr = originalArr.slice(0, index) | |
for (let i=0; i < newArr.length; i++) { | |
//check that the original array contains the value |