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
//ideas: | |
//arrows for dependencies | |
//percent complete fill up bar | |
//who is on the task? | |
//maybe manually set color argument? | |
//helper (end user) functions for adding and adjusting tasks | |
// | |
var w = 800; | |
var h = 400; |
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 upperSectionScore(diceResult){ | |
// handle empty array | |
if(diceResult.length === 0){ | |
return -1; | |
} | |
// will need a way to count the frequency of each number | |
// a variable to store/return the value, and store the largest num freq | |
let frequency = { | |
'1': 0, | |
'2': 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
/** | |
* | |
* Given a dice roll result in Yahtzee (input as an array of 5 integers 1-6), | |
* find the maximum possible score for that roll. | |
* | |
* Yahtzee Scoring Rules | |
* --------------------- | |
* 1 * numberOfOnes | |
* 2 * numOFTwos | |
* 3 * numOfThrees |
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
let singleNumber = function(nums) { | |
// frequency counter | |
let freq = {}; | |
let lonely; | |
// iterate thru array | |
for(let num of nums){ | |
// if num does not exist as key, | |
// create it or increment otherwise | |
if(!freq[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
let singleNumber = function(nums) { | |
// frequency counter way | |
let freq = {}; | |
let lonely; | |
// iterate thru array | |
for(let num of nums){ | |
// if num does not exist as key, | |
// create it or increment otherwise | |
if(!freq[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
let isHappy = (inputNum) => { | |
// keep track of permutations | |
let unhappyNums = []; | |
let newSum = inputNum; | |
// while the inputNum is not in the array | |
while(!unhappyNums.includes(newSum)) { | |
unhappyNums.push(newSum); | |
// calculate new sum by converting to str, | |
// split by character then add the sum of each squared digit |
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
/** | |
* Given at least one number | |
* find the total from a | |
* contiguous set of numbers | |
*/ | |
let maxSubArray = function(nums) { | |
// setting to -infinity handles | |
// negative comparisons | |
let max = -Infinity; | |
temp = -Infinity; |
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
/** | |
* @param {number[]} nums | |
* @return {void} Do not return anything, modify nums in-place instead. | |
*/ | |
let moveZeroes = function(nums) { | |
// two pointers, left & right for beginning and end of array | |
let left = 0; | |
let right = nums.length-1; | |
while(left < right) { | |
let element = nums[left]; |
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
let maxProfit = function(prices) { | |
// two pointers -- buy & sell | |
let buy = 0; | |
let sell = 1; | |
let buyPrice = 0; | |
let sellPrice = 0; | |
let price = 0; | |
while(sell < prices.length) { | |
if(prices[buy] < prices[sell]) { |
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
let countElements = function(arr) { | |
// returning a counter of times a number x + 1 | |
// is found in an array | |
let count = 0; | |
// need storage to keep track of x + 1 frequency | |
let storage = {}; | |
for(let num of arr){ | |
// if a number x + 1 is in the array | |
if(arr.indexOf(num + 1) > -1) { |
OlderNewer