Skip to content

Instantly share code, notes, and snippets.

View Arieg419's full-sized avatar

Omer Goldberg Arieg419

View GitHub Profile
@Arieg419
Arieg419 / mergeMeetings.js
Last active December 17, 2016 10:11
Merge Meetings
// Our input. An array of objects containing all original meeting times.
[
{startTime: 0, endTime: 1},
{startTime: 3, endTime: 5},
{startTime: 4, endTime: 8},
{startTime: 10, endTime: 12},
{startTime: 9, endTime: 10},
]
// Our output. An array of objects containing all meeting times merged.
// We should consider these meetings as overlapping
[{startTime: 1, endTime: 2}, {startTime: 2, endTime: 3}];
// Overlapping meetings! How can we overlapping meeting programitically?
[{startTime: 4, endTime: 6}, {startTime: 5, endTime: 7}];
function mergeRanges(meetings) {
// sort by start times, slice will return a shallow copy of the array, not affecting original array
var sortedMeetings = meetings.slice().sort(function(a, b) {
return a.startTime > b.startTime ? 1 : -1;
});
// initialize mergedMeetings with the earliest meeting
var mergedMeetings = [sortedMeetings[0]];
var complexObjects = {
complexProp: "1", // access via complexObjects.complexProp
simpleProp: "2", // access via complexObjects.simpleProp
regularProp: 5 // access via complexObjects.regularProp
};
var person = new Map();
person.set("Formal Name", "Kanye West");
person.set("Alias", "Yeezy");
person.set("Goal", "GOAT"); // don't stop reading here!
console.log(person.has("Formal Name")) // true
console.log(person.size); // 3
person.delete("Goal");
// create object with numbers as keys
var object = {
1: "First Name",
2: "Middle Name",
3: "Last Name"
};
console.log(object.1); // Uncaught SyntaxError: Unexpected Number
console.log(object."1"); // Uncaught SyntaxError: Unexpected String
console.log(object[1]); // "First Name"
/*
The following is a "driver" file for your TempTracker.js class.
The TempTrackers class you are creating should support all of these methods,
and return the values commented out, at the end of every console.log function call.
*/
var tmp = new tempTracker();
tmp.insert(1);
var pokemon = {
firstname: 'Pika',
lastname: 'Chu ',
getPokeName: function() {
var fullname = this.firstname + ' ' + this.lastname;
return fullname;
}
};
// Suppose we could access yesterday's stock prices as an array, where:
// The indices are the time in minutes past trade opening time, which was 9:30am local time.
// The values are the price in dollars of Apple stock at that time.
// So if the stock cost $500 at 10:30am, stockPricesYesterday[60] = 500;.
// Write an efficient function that takes stockPricesYesterday and returns the best profit
// I could have made from 1 purchase and 1 sale of 1 Apple stock yesterday.
function waysToReturnChange(denominations, numOfCoins, amount) {
if(amount === 0) return 1; // Perfect!
if(amount < 0) return 0; // No solution exists for negative amount
if(numOfCoins < 0 && amount > 0) return 0; // We don't have coins left!
return;
}