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 lengthOfString(str){ | |
return str.length ? lengthOfString(str.substring(1)) + 1 : 0 | |
} |
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 flatten(nums) { | |
const arr = []; | |
nums.forEach((num: Number[]) => { | |
if (Array.isArray(num)) { | |
arr.push(...flatten(num)); | |
} else { | |
arr.push(num); | |
} | |
}); |
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 checkIfPangram(sentence: string): boolean { | |
let seen = new Set() | |
for(let i=0;i<sentence.length;i++){ | |
seen.add(sentence[i]); | |
} | |
if(seen.size === 26){ | |
return true; | |
} else { | |
return false; |
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
var maxArea = function(height: number[]) { | |
let maxArea = 0; | |
for (let i = 0; i < height.length; i++) { | |
for (let j = i+1; j < height.length; j++) { | |
let h = Math.min(height[i], height[j]); | |
let w = j - i; | |
let area = h * w; | |
maxArea = Math.max(area, maxArea); | |
} | |
} |
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 findProduct(...arr:number[]): number[]{ | |
let rt: number[] = []; | |
let temp = 1; | |
for (let i = 0; i < arr.length; i++) { | |
rt[i] = temp | |
temp *= arr[i] | |
} | |
temp = 1 | |
for (let j = arr.length-1; j >= 0; j--) { | |
rt[j] *= temp |
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
//1 | |
const push = (array: number[], num: number) => { | |
array[array.length] = num; | |
return array | |
} | |
// 2 | |
const pop = (array: number[]) => { | |
array.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
type Restaurant = { | |
name: string, | |
priceBracket: Enumerator<PriceBracket>, | |
deliveryTimeMinutes: number, | |
openHour: string, | |
closeHour: string, | |
distance: number, | |
} | |
type Order = { |
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
type Movie = { | |
readonly title: string, | |
originalTitle?: string, | |
director: string, | |
releaseYear: number, | |
boxOffice: { | |
budget: number, | |
grossUS: number, | |
grossWorldwide: number, | |
}, |
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 twoFer(name: string = "you"): string { | |
return `one for ${name}, one for me` | |
} | |
function isLeapYear(year: number): boolean { | |
return (year % 100 !== 0 && year % 4 ===0) || year % 400 === 0; | |
} |
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
// 1 | |
const indexOf = (arr, item) => arr.indexOf(item); | |
indexOf([1,2,3,4], 3) | |
indexOf([5,6,7,8], 8) | |
indexOf([1,2,3,4], 5) |
NewerOlder