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 Inputs = { | |
playerID: string; | |
}; | |
type Match = { | |
matchID: string; | |
winnerID: string; | |
loserID: string; | |
}; |
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 PlayerRecord = { | |
playerID: string; | |
losses: number; | |
wins: number; | |
}; | |
type PlayerRecords = { | |
[key: string]: PlayerRecord; | |
}; |
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 Inputs = { | |
playerOneID: string; | |
playerTwoID: string; | |
winnerID: string; | |
}; | |
export async function handler(inputs: Inputs) { | |
const { playerOneID, playerTwoID, winnerID } = inputs; | |
if (!playerOneID || !playerTwoID || !winnerID) { |
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
export const findKeyInBox = (box) => { | |
console.log(`Looking in Box ${box.id}`); | |
for (let i = 0; i < box.contents.length; i++) { | |
if (box.contents[i].type === 'key') { | |
console.log(`Found the key in Box ${box.id}!`); | |
return box.id; | |
} | |
if (box.contents[i].type === 'box') { |
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
export const findKeyInBox = (box) => { | |
const pile = []; | |
pile.push(box); | |
while (pile.length > 0) { | |
const currentBox = pile.pop(); | |
console.log(`Looking in Box ${currentBox.id}`); | |
for (let i = 0; i < currentBox.contents.length; i++) { | |
if (currentBox.contents[i].type === 'key') { |
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
export const maxNumberArray = (numbers) => { | |
if (numbers.length <= 1) { | |
return numbers[0]; | |
} | |
const numberA = numbers[0]; | |
const numberB = maxNumberArray(numbers.slice(1)); | |
return numberA > numberB ? numberA : numberB; | |
}; |
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
export const maxNumberArray = (numbers) => { | |
let max = numbers[0]; | |
for (let i = 1; i < numbers.length; i++) { | |
if (numbers[i] > max) { | |
max = numbers[i]; | |
} | |
} | |
return max; |
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
export const sumNumbersArray = (numbers) => { | |
if (numbers.length === 0) { | |
return 0; | |
} | |
return numbers[0] + sumNumbersArray(numbers.slice(1)); | |
}; |
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
export const sumNumbersArray = (numbers) => { | |
let sum = 0; | |
for (let i = 0; i < numbers.length; i++) { | |
sum += numbers[i]; | |
} | |
return sum; | |
}; |
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
export const power = (x, y) => { | |
if (y < 0) { | |
throw new Error( | |
'exponent must be greater than or equal to 0 (for the purposes of this example)' | |
); | |
} | |
if (y === 0) { | |
return 1; | |
} |
NewerOlder