Skip to content

Commit ae540f3

Browse files
author
Scott Ferguson
committed
Initial commit
0 parents  commit ae540f3

File tree

5 files changed

+318
-0
lines changed

5 files changed

+318
-0
lines changed

.replit

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
entrypoint = "index.js"
2+
3+
[interpreter]
4+
command = [
5+
"prybar-nodejs",
6+
"-q",
7+
"--ps1",
8+
"\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
9+
"-i"
10+
]
11+
12+
[nix]
13+
channel = "stable-21_11"
14+
15+
[env]
16+
XDG_CONFIG_HOME = "/home/runner/.config"
17+
18+
[packager]
19+
language = "nodejs"
20+
21+
[packager.features]
22+
packageSearch = true
23+
guessImports = true
24+
enabledForHosting = false
25+
26+
[unitTest]
27+
language = "nodejs"
28+
29+
[languages.javascript]
30+
pattern = "**/{*.js,*.jsx,*.ts,*.tsx}"
31+
32+
[languages.javascript.languageServer]
33+
start = [ "typescript-language-server", "--stdio" ]
34+
35+
[debugger]
36+
support = true
37+
38+
[debugger.interactive]
39+
transport = "localhost:0"
40+
startCommand = [ "dap-node" ]
41+
42+
[debugger.interactive.initializeMessage]
43+
command = "initialize"
44+
type = "request"
45+
46+
[debugger.interactive.initializeMessage.arguments]
47+
clientID = "replit"
48+
clientName = "replit.com"
49+
columnsStartAt1 = true
50+
linesStartAt1 = true
51+
locale = "en-us"
52+
pathFormat = "path"
53+
supportsInvalidatedEvent = true
54+
supportsProgressReporting = true
55+
supportsRunInTerminalRequest = true
56+
supportsVariablePaging = true
57+
supportsVariableType = true
58+
59+
[debugger.interactive.launchMessage]
60+
command = "launch"
61+
type = "request"
62+
63+
[debugger.interactive.launchMessage.arguments]
64+
args = []
65+
console = "externalTerminal"
66+
cwd = "."
67+
environment = []
68+
pauseForSourceMap = false
69+
program = "./index.js"
70+
request = "launch"
71+
sourceMaps = true
72+
stopOnEntry = false
73+
type = "pwa-node"

dsa.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// EASY https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
2+
// EASY-MED https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
3+
// MED https://leetcode.com/problems/longest-substring-without-repeating-characters/

index.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const movieListOne = require("./movieData");
2+
3+
// Make a map of actors to a amount they made
4+
5+
/**
6+
Given an array of movie objects (found in the movieData.js file), write a function that will determine which actor made the most money from their movies.
7+
Each actor in a movie receives an equal percent of the box office earnings.
8+
For example, if BoxOffice was $100 and there were 3 actors, each actor would get $33.33.
9+
The function should return the actor’s name and their earnings as a string.
10+
m = #movies
11+
a = #actors
12+
Time: O(m*a^floor(a,m))
13+
Space: O(a) - Each actor gets a spot in the mapping with a constant size value
14+
*/
15+
function actorEarning(movies) {
16+
const actorMapping = {};
17+
for (let movie of movies) {
18+
let boxOffice = movie.BoxOffice;
19+
if (boxOffice && boxOffice == "N/A") {
20+
continue;
21+
}
22+
boxOffice = boxOffice.replaceAll(",", "").replace("$", "");
23+
const actors = movie.Actors;
24+
for (let actor of actors) {
25+
const actorsMovieEarning = Math.floor(Number(boxOffice)/actors.length)
26+
if (Object.keys(actorMapping).includes(actor)) {
27+
actorMapping[actor] += actorsMovieEarning;
28+
} else {
29+
actorMapping[actor] = actorsMovieEarning;
30+
}
31+
}
32+
}
33+
let highestEarnAmount = Number.NEGATIVE_INFINITY;
34+
let highestEarner = "";
35+
for (let [actor, totalEarn] of Object.entries(actorMapping)) {
36+
if (totalEarn > highestEarnAmount) {
37+
highestEarnAmount = totalEarn;
38+
highestEarner = actor;
39+
}
40+
}
41+
return [highestEarner, "$" + highestEarnAmount.toLocaleString()];
42+
}
43+
44+
// [ 'Daisy Ridley', '$415,515,036' ]
45+
console.log(actorEarning(movieListOne));
46+
47+
/**
48+
* @question Write a function that returns a list of the movies box office values.
49+
* What's the space and time complexity of your implementation?
50+
* */
51+
function moviesBoxOffice(selectedMovies) {
52+
// O(n) time where n is the number of movies
53+
const moviesWithBoxOffice = selectedMovies.filter(
54+
(movie) => movie.hasOwnProperty("BoxOffice") && movie.BoxOffice !== "N/A"
55+
);
56+
// Transform each movie object into an array of Number parsed box office earnings.
57+
// O(n*m) time. We do a replace on each movie's box office which is O(m), where m is the length of the longest BoxOffice string/number
58+
return moviesWithBoxOffice.map((movie) =>
59+
Number(movie.BoxOffice.replace(/[^0-9\.-]+/g, ""))
60+
);
61+
}
62+
63+
// Should be [ 936662225, 309306177, 768946, 1 ]
64+
console.log(moviesBoxOffice(movieListOne));

movieData.js

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
const movieListOne = [
2+
{
3+
Actors: ["Daisy Ridley", "John Boyega", "Oscar Isaac"],
4+
BoxOffice: "$936,662,225",
5+
Country: "United States",
6+
Director: "J.J. Abrams",
7+
Genre: "Action, Adventure, Sci-Fi",
8+
Language: "English",
9+
Metascore: "80",
10+
Plot: "As a new threat to the galaxy rises, Rey, a desert scavenger, and Finn, an ex-stormtrooper, must join Han Solo and Chewbacca to search for the one hope of restoring peace.",
11+
Poster:
12+
"https://m.media-amazon.com/images/M/MV5BOTAzODEzNDAzMl5BMl5BanBnXkFtZTgwMDU1MTgzNzE@._V1_SX300.jpg",
13+
Production: "N/A",
14+
Rated: "PG-13",
15+
Ratings: [
16+
{
17+
Source: "Internet Movie Database",
18+
Value: "7.8/10",
19+
},
20+
{
21+
Source: "Rotten Tomatoes",
22+
Value: "93%",
23+
},
24+
{
25+
Source: "Metacritic",
26+
Value: "80/100",
27+
},
28+
],
29+
Response: "True",
30+
Runtime: "138 min",
31+
Title: "Star Wars: Episode VII - The Force Awakens",
32+
imdbID: "tt2488496",
33+
imdbRating: "7.8",
34+
imdbVotes: "901,554",
35+
},
36+
{
37+
Actors: ["Daisy Ridley", "John Boyega", "Oscar Isaac"],
38+
BoxOffice: "N/A",
39+
Country: "United States",
40+
Director: "Irvin Kershner",
41+
Genre: "Action, Adventure, Fantasy",
42+
Language: "English",
43+
Metascore: "82",
44+
Plot: "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda, while his friends are pursued across the galaxy by Darth Vader and bounty hunter Boba Fett.",
45+
Poster:
46+
"https://m.media-amazon.com/images/M/MV5BYmU1NDRjNDgtMzhiMi00NjZmLTg5NGItZDNiZjU5NTU4OTE0XkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_SX300.jpg",
47+
Production: "N/A",
48+
Rated: "PG",
49+
Ratings: [
50+
{
51+
Source: "Internet Movie Database",
52+
Value: "8.7/10",
53+
},
54+
{
55+
Source: "Rotten Tomatoes",
56+
Value: "94%",
57+
},
58+
{
59+
Source: "Metacritic",
60+
Value: "82/100",
61+
},
62+
],
63+
Response: "True",
64+
Runtime: "124 min",
65+
Title: "Star Wars: Episode V - The Empire Strikes Back",
66+
imdbID: "tt0080684",
67+
imdbRating: "8.7",
68+
imdbVotes: "1,235,361",
69+
},
70+
{
71+
Actors: ["Daisy Ridley", "John Boyega", "Oscar Isaac"],
72+
BoxOffice: "$309,306,177",
73+
Country: "United States",
74+
Director: "Richard Marquand",
75+
Genre: "Action, Adventure, Fantasy",
76+
Language: "English",
77+
Metascore: "58",
78+
Plot: "After a daring mission to rescue Han Solo from Jabba the Hutt, the Rebels dispatch to Endor to destroy the second Death Star. Meanwhile, Luke struggles to help Darth Vader back from the dark side without falling into the Emperor's tr",
79+
Poster:
80+
"https://m.media-amazon.com/images/M/MV5BOWZlMjFiYzgtMTUzNC00Y2IzLTk1NTMtZmNhMTczNTk0ODk1XkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_SX300.jpg",
81+
Production: "N/A",
82+
Rated: "PG",
83+
Ratings: [
84+
{
85+
Source: "Internet Movie Database",
86+
Value: "8.3/10",
87+
},
88+
{
89+
Source: "Rotten Tomatoes",
90+
Value: "82%",
91+
},
92+
{
93+
Source: "Metacritic",
94+
Value: "58/100",
95+
},
96+
],
97+
Response: "True",
98+
Runtime: "131 min",
99+
Title: "Star Wars: Episode VI - Return of the Jedi",
100+
imdbID: "tt0086190",
101+
imdbRating: "8.3",
102+
imdbVotes: "1,010,130",
103+
},
104+
{
105+
Actors: ["Daisy Ridley", "John Boyega", "Oscar Isaac", "Sally Field"],
106+
BoxOffice: "$768,946",
107+
Country: "United States",
108+
Director: "Peter Landesman",
109+
Genre: "Biography, Drama, History",
110+
Language: "English",
111+
Metascore: "49",
112+
Plot: 'The story of Mark Felt, who under the name "Deep Throat" helped journalists Bob Woodward and Carl Bernstein uncover the Watergate scandal in 1972.',
113+
Poster:
114+
"https://m.media-amazon.com/images/M/MV5BMjQzMDEwMjMyNF5BMl5BanBnXkFtZTgwNjA1NTA1MzI@._V1_SX300.jpg",
115+
Production: "N/A",
116+
Rated: "PG-13",
117+
Ratings: [
118+
{
119+
Source: "Internet Movie Database",
120+
Value: "6.4/10",
121+
},
122+
{
123+
Source: "Metacritic",
124+
Value: "49/100",
125+
},
126+
],
127+
Response: "True",
128+
Runtime: "103 min",
129+
Title: "Mark Felt: The Man Who Brought Down the White House",
130+
imdbID: "tt5175450",
131+
imdbRating: "6.4",
132+
imdbVotes: "13,098",
133+
},
134+
{
135+
Actors: ["Robert Downey", "John Boyega", "Oscar Isaac"],
136+
BoxOffice: "$1",
137+
Country: "United States",
138+
Director: "Michael Showalter",
139+
Genre: "Comedy, Drama, Romance",
140+
Language: "English",
141+
Metascore: "63",
142+
Plot: "A self-help seminar inspires a sixty-something woman to romantically pursue her younger co-worker.",
143+
Poster:
144+
"https://m.media-amazon.com/images/M/MV5BMTg0NTM3MTI1MF5BMl5BanBnXkFtZTgwMTAzNTAzNzE@._V1_SX300.jpg",
145+
Production: "N/A",
146+
Rated: "R",
147+
Ratings: [
148+
{
149+
Source: "Internet Movie Database",
150+
Value: "6.6/10",
151+
},
152+
{
153+
Source: "Rotten Tomatoes",
154+
Value: "85%",
155+
},
156+
{
157+
Source: "Metacritic",
158+
Value: "63/100",
159+
},
160+
],
161+
Response: "True",
162+
Runtime: "90 min",
163+
Title: "Hello, My Name Is Doris",
164+
imdbID: "tt3766394",
165+
imdbRating: "6.6",
166+
imdbVotes: "20,319",
167+
},
168+
];
169+
170+
module.exports = movieListOne

replit.nix

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ pkgs }: {
2+
deps = [
3+
pkgs.nodejs-16_x
4+
pkgs.nodePackages.typescript-language-server
5+
pkgs.nodePackages.yarn
6+
pkgs.replitPackages.jest
7+
];
8+
}

0 commit comments

Comments
 (0)