Skip to content

Instantly share code, notes, and snippets.

//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;
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,
/**
*
* 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
@javi-aire
javi-aire / singleNumber.js
Created April 2, 2020 05:24
Challenge 1 of 30 on LeetCode
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]){
@javi-aire
javi-aire / singleNumber.js
Last active April 3, 2020 06:46
Problem 1/30 of LeetCode 30-day challenge
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]){
@javi-aire
javi-aire / happyNumber.js
Last active April 3, 2020 06:47
Problem 2/30 of LeetCode 30-day challenge
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
@javi-aire
javi-aire / maxSubArray.js
Last active April 4, 2020 05:50
Problem 3/30 of LeetCode 30-day challenge (main solution from article, added comments for understanding)
/**
* 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;
@javi-aire
javi-aire / moveZeroes.js
Created April 5, 2020 09:13
Problem 4/30 of LeetCode 30-day challenge
/**
* @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];
@javi-aire
javi-aire / maxProfit.js
Created April 6, 2020 02:34
Problem 5/30 of LeetCode 30-day challenge
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]) {
@javi-aire
javi-aire / countElements.js
Created April 7, 2020 23:07
Problem 7/30 of LeetCode 30-day challenge
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) {