Created
August 5, 2019 17:21
-
-
Save Omrika/a7613d8fdddaf1143c5163df52592e31 to your computer and use it in GitHub Desktop.
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
//check in/out citi bike | |
// User object | |
// Bikes object | |
// Stations object | |
// Location object | |
const stations = [ | |
{ | |
id: 1, | |
location: "downtown bk" | |
}, | |
{ | |
id: 2, | |
location: "BedStuy" | |
} | |
] | |
const bikes = | |
[ | |
{ id: 1, name: "citibike one"}, | |
{ id: 2, name: "citibike two"}, | |
] | |
const user = [ | |
{id: 22, name: "Scott"}, | |
{id: 23, name: "Omrika"}, | |
{id: 24, name: "Sarah"}, | |
] | |
const rides = [ | |
{id: 23, bike_id: 1, user_id: 22, checkin_station_id: 1, checkout_station_id: 2}, | |
{id: 24, bike_id: 1, user_id: 23, checkin_station_id: 1, checkout_station_id: 2}, | |
{id: 25, bike_id: 2, user_id: 23, checkin_station_id: 1, checkout_station_id: 2}, | |
] | |
function getCitiBike(user, bike, station) { | |
const userId = user.id | |
const bikeId = bike.id | |
const pickUpStation = station.id | |
const lastRideIndex = rides.length - 1 | |
const lastRide = rides[lastRideIndex] | |
const rideObject = {id: lastRide.id + 1} | |
rideObject.bike_id = bikeId | |
rideObject.user_id = userId | |
rideObject.checkout_station_id = pickUpStation | |
rides.push(rideObject) | |
return rideObject | |
} | |
function dropOffCitiBike(bikeId, stationId) { | |
const currentRide = rides.find(function(obj){ | |
return obj.bike_id === bikeId && !obj.checkin_station_id | |
}) | |
currentRide.checkin_station_id = stationId | |
return currentRide | |
} | |
getCitiBike(user[0], bikes[0], stations[0]) | |
dropOffCitiBike(bikes[0].id, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment