Skip to content

Instantly share code, notes, and snippets.

View Arieg419's full-sized avatar

Omer Goldberg Arieg419

View GitHub Profile
// 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.
var pokemon = {
firstname: 'Pika',
lastname: 'Chu ',
getPokeName: function() {
var fullname = this.firstname + ' ' + this.lastname;
return fullname;
}
};
var pokemon = {
firstname: 'Pika',
lastname: 'Chu ',
getPokeName: function() {
var fullname = this.firstname + ' ' + this.lastname;
return fullname;
}
};
var pokemonName = function(snack, hobby) {
var pokemon = {
firstname: 'Pika',
lastname: 'Chu ',
getPokeName: function() {
var fullname = this.firstname + ' ' + this.lastname;
return fullname;
}
};
var pokemonName = function() {
/*
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 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"
var complexObjects = {
complexProp: "1", // access via complexObjects.complexProp
simpleProp: "2", // access via complexObjects.simpleProp
regularProp: 5 // access via complexObjects.regularProp
};
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]];
// 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}];