Skip to content

Instantly share code, notes, and snippets.

View willshepp28's full-sized avatar

Will Sheppard willshepp28

View GitHub Profile
def kids_with_candies(candies, extra_candies)
greatest_value = candies.max
candies.map { |candy|
(candy += extra_candies) >= greatest_value ? true : false
}
end
# @param {Integer[]} candies
# @param {Integer} extra_candies
# @return {Boolean[]}
def kids_with_candies(candies, extra_candies)
greatest_value = 0
#loop through the array and store the value with the greatest value
candies.each do |candy|
greatest_value = candy if candy > greatest_value
end
/**
* @param {number[]} nums
* @return {number}
*/
var singleNumber = function(nums) {
let obj = {};
for(let i = 0; i < nums.length; i++) {
if(!obj[nums[i]]) {
var restoreString = function(s, indices) {
let shuffled = [];
for(let i = 0; i < s.length; i++) {
shuffled[indices[i]] = s[i];
}
return shuffled.join("");
};
/**
* @param {string} command
* @return {string}
*/
var interpret = function(command) {
let output = '';
for(let i = 0; i < command.length; i++) {
if(command[i] === "G") {
output += "G"
# @param {String} command
# @return {String}
def interpret(command)
output = ""
command.split('').each_with_index { |character, idx|
if character == "G"
output += "G"
elsif character == "("
@willshepp28
willshepp28 / league.api.js
Created December 7, 2020 20:13
getting leagues by radius, then filter the leagues by budget
const router = require("express").Router();
const model = require("../db/models");
const {addLeagueValidator, findLeagueValidator} = require("../helpers/validation/league.validation");
const { findLeagueByName, getLeaguesByRadiusRaw } = require("../services/league/league.service");
const leaguesInBudget = require("../helpers/budget.helper");
// GET path to find a league
// Given a total budget, a radius, and a location, this service should return enough leagues to spend up to the budget, sponsoring as many leagues as possible without going over it
@willshepp28
willshepp28 / leagues.api.js
Last active December 7, 2020 20:06
using getleaguesbyradius to get all leageus within a certain radius.
const router = require("express").Router();
const model = require("../db/models");
const {addLeagueValidator, findLeagueValidator} = require("../helpers/validation/league.validation");
const { findLeagueByName, getLeaguesByRadiusRaw } = require("../services/league/league.service");
// GET path to find a league
// Given a total budget, a radius, and a location, this service should return enough leagues to spend up to the budget, sponsoring as many leagues as possible without going over it
router.get("/", findLeagueValidator, async(request, response) => {
const model = require("../../db/models");
const Sequelize = require("sequelize")
const getLeaguesByRadiusRaw = async(request) => {
return await model.sequelize.query(
`SELECT name, location, price
FROM "Leagues"
WHERE ST_DWithin(location, ST_MakePoint(${request.body.longitude},${request.body.latitude})::geography, ${request.body.radius * 1609.344})
AND price BETWEEN 0 AND ${request.body.budget}
@willshepp28
willshepp28 / app.js
Created December 3, 2020 23:01
app.js with dotenv bcrypt
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const bcrypt = require("bcrypt");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))