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 dailyTemp = (arr) => { | |
| const answer = [] | |
| for (let i = 0; i < arr.length; i++) { | |
| const current = arr[i]; | |
| const higher = arr.slice(i).findIndex((item) => item > current); | |
| higher >= 0 ? answer.push(higher) : answer.push(0); | |
| } | |
| return answer; | |
| } |
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
| let array = [ | |
| [1,2,3], | |
| [4,5,6], | |
| [7,8,9] | |
| ] | |
| const flip = (arr, type) => { | |
| let newList = []; | |
| if (type === 'horizontal') { |
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 isBitonic = (arr) => { | |
| let peakNumber = 0; | |
| for (let i = 0; i < arr.length; i++) { | |
| if(arr[i] > peakNumber) { | |
| peakNumber = arr[i]; | |
| } | |
| if(arr[i] === peakNumber && arr[i] > arr[i + 1]) { | |
| console.log('extra credit: ', peakNumber); | |
| return true |
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
| // Given an array of integers, return the majority element. | |
| // If there is no majority element, return if the array is majority even or odd numbers, | |
| // and if there is none, say so. | |
| function findMajorityNumber(arr) { | |
| const counts = new Map(); | |
| let evenCount = 0; | |
| let oddCount = 0; | |
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 numbersBetween(num1, num2) { | |
| const min = Math.min(num1, num2); | |
| const max = Math.max(num1, num2); | |
| const result = []; | |
| for (let i = min + 1; i < max; i++) { | |
| result.push(i); | |
| } | |
| return result; |
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
| /* | |
| Given a list of words and a dictionary of letter scores, find the word with the highest score | |
| according to the rules: score = word_length * (sum of letter scores in the word). | |
| If there are multiple words with the same highest score, | |
| return the lexicographically smallest one. | |
| */ | |
| const wordList = ["apple", "banana", "cherry", "date", "fig"]; | |
| const letterScores = [...Array(26).keys()].reduce( |
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 add = (nums) => { | |
| const allNums = nums.toString().split("").map((num) => parseInt(num)); | |
| return allNums.reduce((acc, cur) => acc + cur, 0); | |
| }; | |
| const multiply = (nums) => { | |
| const allNums = nums.toString().split("").map((num) => parseInt(num)); | |
| return allNums.reduce((acc, cur) => acc * cur, 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 fetchStrengths = async (url) => { | |
| try { | |
| const strengths = await fetch(url); | |
| const allStrengths = await strengths.json(); | |
| const damageCaused = allStrengths.damage_relations.double_damage_from.map( | |
| (item) => item.name | |
| ); | |
| const damageDone = allStrengths.damage_relations.double_damage_to.map( | |
| (item) => item.name | |
| ); |