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
def kids_with_candies(candies, extra_candies) | |
greatest_value = candies.max | |
candies.map { |candy| | |
(candy += extra_candies) >= greatest_value ? true : false | |
} | |
end |
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 {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 |
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 {number} | |
*/ | |
var singleNumber = function(nums) { | |
let obj = {}; | |
for(let i = 0; i < nums.length; i++) { | |
if(!obj[nums[i]]) { |
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
var restoreString = function(s, indices) { | |
let shuffled = []; | |
for(let i = 0; i < s.length; i++) { | |
shuffled[indices[i]] = s[i]; | |
} | |
return shuffled.join(""); | |
}; |
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 {string} command | |
* @return {string} | |
*/ | |
var interpret = function(command) { | |
let output = ''; | |
for(let i = 0; i < command.length; i++) { | |
if(command[i] === "G") { | |
output += "G" |
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 {String} command | |
# @return {String} | |
def interpret(command) | |
output = "" | |
command.split('').each_with_index { |character, idx| | |
if character == "G" | |
output += "G" | |
elsif character == "(" |
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
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 |
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
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) => { |
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
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} |
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
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 })) |
NewerOlder