From c9093f7f2e71bc6b19909a452c37cb72eb3c281b Mon Sep 17 00:00:00 2001 From: Chris McDermut Date: Thu, 7 May 2020 22:27:11 -0700 Subject: [PATCH 1/6] saving shit --- .../bookingManagement/bookingManagement.js | 64 ++++ .../bookingManagement.test.js | 93 +++++ .../bookingManagementNotes.md | 124 +++++++ .../bookingManagementSpec.md | 43 +++ .../playlistRefactor/playlistRefactor.js | 5 + .../playlistRefactor/playlistRefactor.test.js | 256 ++++++++++++++ .../playlistRefactor/playlistRefactorNotes.md | 334 ++++++++++++++++++ .../playlistRefactor/playlistRefactorSpec.md | 73 ++++ challenges/shortestString/shortestString.js | 3 + helpers/generateSolution.js | 2 +- 10 files changed, 996 insertions(+), 1 deletion(-) create mode 100644 challenges/bookingManagement/bookingManagement.js create mode 100644 challenges/bookingManagement/bookingManagement.test.js create mode 100644 challenges/bookingManagement/bookingManagementNotes.md create mode 100644 challenges/bookingManagement/bookingManagementSpec.md create mode 100644 challenges/playlistRefactor/playlistRefactor.js create mode 100644 challenges/playlistRefactor/playlistRefactor.test.js create mode 100644 challenges/playlistRefactor/playlistRefactorNotes.md create mode 100644 challenges/playlistRefactor/playlistRefactorSpec.md diff --git a/challenges/bookingManagement/bookingManagement.js b/challenges/bookingManagement/bookingManagement.js new file mode 100644 index 00000000..4e29572f --- /dev/null +++ b/challenges/bookingManagement/bookingManagement.js @@ -0,0 +1,64 @@ +function BookManager() { + this.books = []; + + this.createBook = function (id, title) { + // TODO: return false if the book id already exists + id = parseInt(id); + let book = new Object(); + book.id = id; + book.title = title; + this.books = [...this.books, book]; + return true; + }; + + this.updateBook = function (id, title) { + // TODO: return false if the book doesn't exist + + id = parseInt(id); + this.books = this.books.filter(book => { + return { + id: id, + title: title + }; + }); + return true; + }; + + this.deleteBook = function (id) { + // TODO: return false if the book doesn't exist + + id = parseInt(id); + const book = this.books.find(book => book.id === id); + delete book; + return true; + }; + + this.findBookById = function (id) { + return this.books.find(book => book.id === parseInt(id)); + }; + + this.findBookByTitle = function (title) { + return this.books.find(book => book.title === title); + }; +} + +// Do NOT edit the code below this comment. +// You should be able to complete this test without editing below this comment. + +const bookManager = new BookManager(); + +function bookManagementRefactor(operations) { + // Calls corresponding methods of bookManager based on the input + return operations.map(operation => { + const [methodName, ...params] = operation; + let result = bookManager[methodName].call(bookManager, ...params); + return result === undefined ? "null" : JSON.stringify(result); + }); +} + + +function bookingManagement(input) { + +} + +module.exports = bookingManagement diff --git a/challenges/bookingManagement/bookingManagement.test.js b/challenges/bookingManagement/bookingManagement.test.js new file mode 100644 index 00000000..14793b0a --- /dev/null +++ b/challenges/bookingManagement/bookingManagement.test.js @@ -0,0 +1,93 @@ +const bookingManagement = require('./bookingManagement'); + +const testOne = { + input: '', + output: '', +}; + +describe('bookingManagement Test', () => { + test('testOne', () => { + const result = bookingManagement(testOne.input); + expect(result).toEqual(testOne.output); + }); +}); + + +operations: +[["createBook","10","Book_10"], + ["createBook","10","Book_10"], + ["updateBook","10","New_Book_10"], + ["deleteBook","9"], + ["findBookById","9"], + ["findBookById","10"], + ["findBookByTitle","Book_10"], + ["findBookByTitle","New_Book_10"]] +Expected Output: +["true", + "false", + "true", + "false", + "null", + "{\"id\":10,\"title\":\"New_Book_10\"}", + "null", + "{\"id\":10,\"title\":\"New_Book_10\"}"] + + + +operations: [["createBook","10","Book 10"]] +Expected Output: +["true"] + +operations: [["updateBook","462","Book 462"]] +Expected Output: +["false"] + +Input: +operations: +[["createBook","23","The Greeen Book"], + ["createBook","23","The Red Book"], + ["createBook","22","The Green Book"], + ["updateBook","23","The Green Book"], + ["findBookById","23"], + ["findBookById","22"], + ["updateBook","22","The Red Book"], + ["findBookByTitle","The Red Book"], + ["findBookByTitle","The Green Book"]] +Expected Output: +["true", + "false", + "true", + "true", + "{\"id\":23,\"title\":\"The Green Book\"}", + "{\"id\":22,\"title\":\"The Green Book\"}", + "true", + "{\"id\":22,\"title\":\"The Red Book\"}", + "{\"id\":23,\"title\":\"The Green Book\"}"] +Click the "Run Tests" button to see output and console logs. + +Input: +operations: +[["createBook","733","Book 733"], + ["findBookById","236"]] +Expected Output: +["true", + "null"] +Click the "Run Tests" button to see output and console logs. + +Input: +operations: +[["createBook","733","Book 733"], + ["findBookById","733"]] +Expected Output: +["true", + "{\"id\":733,\"title\":\"Book 733\"}"] + + Input: +operations: +[["createBook","269","Book 269"], + ["updateBook","454","Book 454"], + ["findBookByTitle","Book 269"]] +Expected Output: +["true", + "false", + "{\"id\":269,\"title\":\"Book 269\"}"] diff --git a/challenges/bookingManagement/bookingManagementNotes.md b/challenges/bookingManagement/bookingManagementNotes.md new file mode 100644 index 00000000..51387ddc --- /dev/null +++ b/challenges/bookingManagement/bookingManagementNotes.md @@ -0,0 +1,124 @@ +bookingManagement Notes go here! + + +///////////////////// +function BookManager() { + this.books = []; + + this.createBook = function (id, title) { + // TODO: return false if the book id already exists + + id = parseInt(id); + let book = new Object(); + book.id = id; + book.title = title; + this.books = [...this.books, book]; + return true; + }; + + this.updateBook = function (id, title) { + // TODO: return false if the book doesn't exist + + id = parseInt(id); + this.books = this.books.filter(book => { + return { + id: id, + title: title + }; + }); + return true; + }; + + this.deleteBook = function (id) { + // TODO: return false if the book doesn't exist + + id = parseInt(id); + const book = this.books.find(book => book.id === id); + delete book; + return true; + }; + + this.findBookById = function (id) { + return this.books.find(book => book.id === parseInt(id)); + }; + + this.findBookByTitle = function (title) { + return this.books.find(book => book.title === title); + }; +} + +// Do NOT edit the code below this comment. +// You should be able to complete this test without editing below this comment. + +const bookManager = new BookManager(); + +function bookManagementRefactor(operations) { + // Calls corresponding methods of bookManager based on the input + return operations.map(operation => { + const [methodName, ...params] = operation; + let result = bookManager[methodName].call(bookManager, ...params); + return result === undefined ? "null" : JSON.stringify(result); + }); +} + + +//////////////FINAL +function BookManager() { + this.books = {}; + + this.createBook = function (id, title) { + idl = parseInt(id); /*book id*/ + let bookCreated = false + + if(!this.books.hasOwnProperty(idl)){ + let book = new Object(); + book.id = idl; + book.title = title; + this.books[idl] = book + bookCreated = true + } + return bookCreated + }; + + this.updateBook = function (id, title) { + id = parseInt(id); + let bookUpdated = false; + if(this.books[id]){ + this.books[id]['title'] = title + bookUpdated = true + } + return bookUpdated; + }; + + this.deleteBook = function (id) { + id = parseInt(id); + let bookDeleted = false + if(this.books[id]){ + delete this.books[id] + bookDeleted = true + } + return bookDeleted; + }; + + this.findBookById = function (id) { + return this.books[id] ? this.books[id] : null + }; + + this.findBookByTitle = function (title) { + return Object.values(this.books).find(book => book.title === title); + }; +} + +// Do NOT edit the code below this comment. +// You should be able to complete this test without editing below this comment. + +const bookManager = new BookManager(); + +function bookManagementRefactor(operations) { + // Calls corresponding methods of bookManager based on the input + return operations.map(operation => { + const [methodName, ...params] = operation; + let result = bookManager[methodName].call(bookManager, ...params); + return result === undefined ? "null" : JSON.stringify(result); + }); +} diff --git a/challenges/bookingManagement/bookingManagementSpec.md b/challenges/bookingManagement/bookingManagementSpec.md new file mode 100644 index 00000000..41eac767 --- /dev/null +++ b/challenges/bookingManagement/bookingManagementSpec.md @@ -0,0 +1,43 @@ +bookingManagement Spec go here! + +You are given a class that handles operations with books, however it is not complete and might have some issues, your task is to refactor it, fix the issues and add the missing parts. + +Each book is described by 2 fields: id and title. + +The methods that should be supported are listed below: + +createBook(id, title) - creates new book. Returns false if the book with such id already exists, and true otherwise; +updateBook(id, title) - updates provided book. Returns false if the book with such id does not exist, and true otherwise. +deleteBook(id) - deletes provided book. Returns false if the book with such id does not exist, and true otherwise. +findBookById(id) - find book by id. Returns the book, if the book with such id exists, and null otherwise. +findBookByTitle(title) - find book by title. Returns the book, if the book with such title exists, and null otherwise. It is guaranteed that at any time there are no two books with the same title. +Implement all these methods. + +Example + +For operations = [["createBook", "10", "Book_10"], ["createBook", "10", "Book_10"], ["updateBook", "10", "New_Book_10"], ["deleteBook", "9"],["findBookById", "9"], ["findBookById", "10"], ["findBookByTitle", "Book_10"], ["findBookByTitle", "New_Book_10"]], the output should be +bookManagementRefactor(operations) = ["true", "false", "true", "false", "null", "{"id":10,"title":"New_Book_10"}", "null", "{"id":10,"title":"New_Book_10"}"]. + +Input/Output + +[execution time limit] 4 seconds (js) + +[input] array.array.string operations + +An array of operations desribed above. + +Guaranteed constraints: +1 ≤ operations.length ≤ 103, +2 ≤ operations[i].length ≤ 3. + +[output] array.string + +An array with ith element equal to the result of the ith operation. +[JavaScript (ES6)] Syntax Tips + +// Prints help message to the console +// Returns a string +function helloWorld(name) { + console.log("This prints to the console when you Run Tests"); + return "Hello, " + name; +} diff --git a/challenges/playlistRefactor/playlistRefactor.js b/challenges/playlistRefactor/playlistRefactor.js new file mode 100644 index 00000000..03ea41f6 --- /dev/null +++ b/challenges/playlistRefactor/playlistRefactor.js @@ -0,0 +1,5 @@ +function playlistRefactor(input) { + +} + +module.exports = playlistRefactor diff --git a/challenges/playlistRefactor/playlistRefactor.test.js b/challenges/playlistRefactor/playlistRefactor.test.js new file mode 100644 index 00000000..ade5acfc --- /dev/null +++ b/challenges/playlistRefactor/playlistRefactor.test.js @@ -0,0 +1,256 @@ +const playlistRefactor = require('./playlistRefactor') + +const testOne = { + input: '', + output: '' +} + +describe('playlistRefactor Test', () => { + + test('testOne', ()=>{ + let result = playlistRefactor(testOne.input) + expect(result).toEqual(testOne.output); + }) + +}) + + +commands: +["add", + "play", + "get", + "add", + "play", + "play", + "get", + "play", + "get"] +names: +["I Still Miss Someone", + "I Still Miss Someone", + "", + "Toxicity", + "I Still Miss Someone", + "I Still Miss Someone", + "", + "I Still Miss Someone", + ""] +parameters: [1, 751, 0, 584, 1, 824, 0, 220, 0] +Output: +["[Track(name = I Still Miss Someone, duration = 1, pausedOn = 750)]", + "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 1573), Track(name = Toxicity, duration = 584, pausedOn = 0)]", + "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 1792), Track(name = Toxicity, duration = 584, pausedOn = 0)]"] +Expected Output: +["[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0)]", + "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 584, pausedOn = 0)]", + "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 584, pausedOn = 0)]"] +Console Output: +PLAY CALLED FOR TIME +751 +PLAY CALLED FOR TIME +1 +PLAY CALLED FOR TIME +824 +PLAY CALLED FOR TIME +220 + +nput: +commands: +["add", + "add", + "add", + "add", + "get", + "move", + "get", + "move", + "get", + "add", + "add", + "get", + "move", + "get", + "move", + "get"] +names: +["\"Long Gone(From the Bowlin Green)\"", + "Symphony #9 in D minor(\"Choral\"),Op. 125", + "I Walk the Line", + "Jackie Cane", + "", + "Symphony #9 in D minor(\"Choral\"),Op. 125", + "", + "I Walk the Line", + "", + "OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo", + "Toxicity", + "", + "Toxicity", + "", + "Toxicity", + ""] +parameters: [1, 509, 1, 568, 0, 0, 0, 2, 0, 1, 1000, 0, 3, 0, 2, 0] +Output: +["[Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]"] +Expected Output: +["[Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0)]", + "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0)]"] +Console Output: +Empty + + +//////// + +Time's Up! +The test is now over, and you may not make further changes. +You have one minute to submit your work if you have not done so already. +dataMeans +( +0:00:53 +) +Codewriting + +You are given the files data.json and data.csv in the /root/devops/ directory. + +data.json contains a JSON array of objects with the following format: + +{ + "id": string, + "id2": string, + "key": string, + "created": number, // UNIX timestamp (UTC) in milliseconds + "district": string +} +while data.csv has the following columns + +id,sla,overdue,x,y,type +string,number,number,number,number,number +where id corresponds to id in data.json. + +Find out which day of the week has the lowest mean overdue value, and output it to the console. + +Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. + +Example + +For the following data.json + +[ + {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, + {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, + {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, + {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, + {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, + {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} +] +and data.csv + +id,sla,overdue,x,y,type +4,10.0,-8.98,3105443.57,13832598.28,3.0 +1,14.0,-7.79,3047695.62,13826869.96,3.0 +3,10.0,-8.59,3078170.34,13820368.28,3.0 +2,10.0,-8.98,3105443.57,13832598.28,3.0 +7,14.0,-7.79,3047695.62,13826869.96,3.0 +0,10.0,-8.59,3078170.34,13820368.28,3.0 +the output for this should be: + +Friday +C +[execution time limit] 25 seconds (js) +JavaScript (ES6) +12 +console.log('Hello world'); + +TESTS +Test 1 +Input: +View the setup script +Expected Output: +Friday +C +Click the "Run Tests" button to see output and console logs. +Test 2 +Test 3 +Test 4 +Test 5 +Test 6 +Formatting +Editor Mode +VS Code +Theme +Dark +Tab Size +Auto +Font Size +14px +Auto-brackets +Minimap +Code Completion +Error Highlighting +Hotkeys +CTRL/CMD + Enter +Submit +CTRL/CMD + R +Run +CTRL/CMD + S +Save +0/300 + +resetTrack + +You are given the files data.json and data.csv in the /root/devops/ directory. + +data.json contains a JSON array of objects with the following format: + +{ + "id": string, + "id2": string, + "key": string, + "created": number, // UNIX timestamp (UTC) in milliseconds + "district": string +} +while data.csv has the following columns + +id,sla,overdue,x,y,type +string,number,number,number,number,number +where id corresponds to id in data.json. + +Find out which day of the week has the lowest mean overdue value, and output it to the console. + +Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. + +Example + +For the following data.json + +[ + {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, + {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, + {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, + {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, + {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, + {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} +] +and data.csv + +id,sla,overdue,x,y,type +4,10.0,-8.98,3105443.57,13832598.28,3.0 +1,14.0,-7.79,3047695.62,13826869.96,3.0 +3,10.0,-8.59,3078170.34,13820368.28,3.0 +2,10.0,-8.98,3105443.57,13832598.28,3.0 +7,14.0,-7.79,3047695.62,13826869.96,3.0 +0,10.0,-8.59,3078170.34,13820368.28,3.0 +the output for this should be: + +Friday +C +[execution time limit] 25 seconds (js) diff --git a/challenges/playlistRefactor/playlistRefactorNotes.md b/challenges/playlistRefactor/playlistRefactorNotes.md new file mode 100644 index 00000000..cdb358bf --- /dev/null +++ b/challenges/playlistRefactor/playlistRefactorNotes.md @@ -0,0 +1,334 @@ +playlistRefactor Notes go here! + +//////////// +class Track { + constructor(name, duration) { + this.name = name; + this.duration = duration; + this.pausedOn = 0; + } + + play(time) { + // TODO: implement this method + } + + reset() { + // TODO: implement this method + } + + toString() { + return `Track(name = ${this.name}, duration = ${this.duration}, pausedOn = ${this.pausedOn})`; + } +} + +class Playlist { + constructor() { + this.trackList = []; + } + + addTrack(name, duration) { + // TODO: implement this method + } + + deleteTrack(name) { + // TODO: implement this method + } + + playTrack(name, time) { + // TODO: implement this method + } + + resetTrack(name) { + // TODO: implement this method + } + + trackIndexByName(name) { + // TODO: implement this method + return -1; + } + + moveTrack(name, toIndex) { + const index = this.trackIndexByName(name); + if (index === toIndex) { + return; + } + // TODO: complete the implementation of this method + } + + toString() { + return '[' + this.trackList.map(track => track.toString()).join(', ') + ']'; + } +} + +function playlistRefactoring(commands, names, parameters) { + const playlist = new Playlist(); + const result = []; + + for (let i = 0; i < commands.length; i++) { + if (commands[i] === 'add') { + playlist.addTrack(names[i], parameters[i]); + } else if (commands[i] === 'delete') { + playlist.deleteTrack(names[i]); + } else if (commands[i] === 'play') { + playlist.playTrack(names[i], parameters[i]); + } else if (commands[i] === 'reset') { + if (names[i] === '') { + playlist.resetTrack(); + } else { + playlist.resetTrack(names[i]); + } + } else if (commands[i] === 'move') { + playlist.moveTrack(names[i], parameters[i]); + } else { // commands[i] === 'get' + result.push(playlist.toString()); + } + } + + return result; +} + + +//////////////////////////// +class Track { + constructor(name, duration) { + this.name = name; + this.duration = duration; + this.pausedOn = 0; + } + + play(time) { + console.log('PLAY CALLED FOR TIME') + console.log(time) + // TODO: implement this method + // console.log('this.pausedOn') + // console.log(this.pausedOn) + // console.log('time') + // console.log(time) + if((this.pausedOn+time)<=this.duration){ + this.pausedOn+=time + } else { + this.pausedOn = ((this.pausedOn+time)-this.duration) + } + // console.log('AFTER this.pausedOn') + // console.log(this.pausedOn) + } + + reset() { + this.pausedOn = 0 + } + + toString() { + return `Track(name = ${this.name}, duration = ${this.duration}, pausedOn = ${this.pausedOn})`; + } +} + +class Playlist { + constructor() { + this.trackList = []; + } + + addTrack(name, duration) { + let newTrack = new Track(name,duration); + this.trackList.push(newTrack) + } + + deleteTrack(name) { + this.trackList = this.trackList.filter((track)=>{ + return track.name !== name + }) + } + + playTrack(name, time) { + // TODO: implement this method + this.trackList.forEach((track,i)=>{ + if(track.name === name){ + this.trackList[i].play(time) + } + }) + } + + resetTrack(name) { + // TODO: implement this method + if(name){ + this.trackList.forEach((track,i)=>{ + if(track.name === name){ + this.trackList[i].reset() + } + }) + } else {this.trackList.forEach((track,i)=>{ + track.reset() + }) + } + } + + trackIndexByName(name) { + // TODO: implement this method + return -1; + } + + moveTrack(name, toIndex) { + const index = this.trackIndexByName(name); + if (index === toIndex) { + return; + } + // TODO: complete the implementation of this method + } + + toString() { + return '[' + this.trackList.map(track => track.toString()).join(', ') + ']'; + } +} + +function playlistRefactoring(commands, names, parameters) { + const playlist = new Playlist(); + const result = []; + + for (let i = 0; i < commands.length; i++) { + if (commands[i] === 'add') { + playlist.addTrack(names[i], parameters[i]); + } else if (commands[i] === 'delete') { + playlist.deleteTrack(names[i]); + } else if (commands[i] === 'play') { + playlist.playTrack(names[i], parameters[i]); + } else if (commands[i] === 'reset') { + if (names[i] === '') { + playlist.resetTrack(); + } else { + playlist.resetTrack(names[i]); + } + } else if (commands[i] === 'move') { + playlist.moveTrack(names[i], parameters[i]); + } else { // commands[i] === 'get' + result.push(playlist.toString()); + } + } + + return result; +} + + +//////////////////////// +class Track { + constructor(name, duration) { + this.name = name; + this.duration = duration; + this.pausedOn = 0; + } + + play(time) { + console.log('PLAY CALLED FOR TIME') + console.log(time) + // TODO: implement this method + // console.log('this.pausedOn') + // console.log(this.pausedOn) + // console.log('time') + // console.log(time) + if((this.pausedOn+time){ + return track.name !== name + }) + } + + playTrack(name, time) { + this.trackList.forEach((track,i)=>{ + if(track.name === name){ + track.play(time) + } + }) + } + + resetTrack(name) { + // TODO: implement this method + if(name){ + this.trackList.forEach((track,i)=>{ + if(track.name === name){ + this.trackList[i].reset() + } + }) + } else {this.trackList.forEach((track,i)=>{ + track.reset() + }) + } + } + + trackIndexByName(name) { + // TODO: implement this method + return findWithAttr(this.trackList,'name',name) + } + + moveTrack(name, toIndex) { + const index = this.trackIndexByName(name); + if (index === toIndex) { + return; + } + this.trackList.splice(toIndex, 0, this.trackList[index]) + } + + toString() { + return '[' + this.trackList.map(track => track.toString()).join(', ') + ']'; + } +} + +function findWithAttr(array, attr, value) { + for(var i = 0; i < array.length; i += 1) { + if(array[i][attr] === value) { + return i; + } + } + return -1; +} + +function playlistRefactoring(commands, names, parameters) { + const playlist = new Playlist(); + const result = []; + + for (let i = 0; i < commands.length; i++) { + if (commands[i] === 'add') { + playlist.addTrack(names[i], parameters[i]); + } else if (commands[i] === 'delete') { + playlist.deleteTrack(names[i]); + } else if (commands[i] === 'play') { + playlist.playTrack(names[i], parameters[i]); + } else if (commands[i] === 'reset') { + if (names[i] === '') { + playlist.resetTrack(); + } else { + playlist.resetTrack(names[i]); + } + } else if (commands[i] === 'move') { + playlist.moveTrack(names[i], parameters[i]); + } else { // commands[i] === 'get' + result.push(playlist.toString()); + } + } + + return result; +} diff --git a/challenges/playlistRefactor/playlistRefactorSpec.md b/challenges/playlistRefactor/playlistRefactorSpec.md new file mode 100644 index 00000000..f8c09f32 --- /dev/null +++ b/challenges/playlistRefactor/playlistRefactorSpec.md @@ -0,0 +1,73 @@ +playlistRefactor Spec go here! + +You are given the structure of a class that handles basic music playlist operations. Each playlist consists of several tracks. Your task is to complete the implementation of the missing methods. + +The class Track has 3 properties: + +name - the name of the track represented as a non-empty string consisting of no more then 100 ASCII-characters. +duration - an integer representing the duration of the track, in seconds. +pausedOn - the second on which the track was paused the last time it was played. +You must complete the implementation of the following methods: + +play(time) - plays the track starting from moment pausedOn for time seconds. If the track ends before time seconds are left, it starts over. +reset() - resets the track (sets pausedOn to 0). +The main class Playlist contains only the property trackList - the list of tracks in the playlist. Note that the order of the tracks in the playlist is important. + +You must complete the implementation of the following methods: + +addTrack(name, duration) - adds a track with the given name and duration to the end of the playlist. It is guaranteed that there is no track with the given name when this method is called. +deleteTrack(name) - deletes the track with the given name. It is guaranteed that there is exactly 1 track with the given name in the playlist when this method is called. +playTrack(name, time) - plays the track with the given name for the given number of seconds. It is guaranteed that there is exactly 1 track with the given name in the playlist when this method is called. +resetTrack(name) - resets the track with the given name. If no name is given, this method resets all the tracks in the playlist. It is guaranteed that there is exactly 1 track with the given name (if a name is given) in the playlist when this method is called. +moveTrack(name, toIndex) - moves the track with the given name to the given index. Does not change the order of the other tracks in the playlist. It is guaranteed that there is exactly 1 track with the given name in the playlist when this method is called. +Please do not edit the rest of the existing methods. However, feel free to add any other new methods to the classes if they will help you to solve the problem + +Example + +For commands = ["add", "play", "get", "add", "get"], names = ["Clair de Lune", "Clair de Lune", "", "Toxicity", ""], and parameters = [303, 603, 0, 283, 0], the output should be + +playlistRefactoring(commands, names, parameters) = [ + "[Track(name = Clair de Lune, duration = 303, pausedOn = 300)]", + "[Track(name = Clair de Lune, duration = 303, pausedOn = 300), Track(name = Toxicity, duration = 283, pausedOn = 0)]" +] +Input/Output + +[execution time limit] 4 seconds (js) + +[input] array.string commands + +commands[i] is one of the following strings: + +add; +delete; +play; +reset; +move; +get. +Guaranteed constraints: +4 ≤ commands.length ≤ 100. + +[input] array.string names + +names[i] can have length 0 only for reset and get commands, in all other cases the name of the track is guaranteed to be a non-empty string. + +Guaranteed constraints: +names.length = commands.length, +0 ≤ names[i].length ≤ 100. + +[input] array.integer parameters + +Guaranteed constraints: +parameters.length = commands.length, +0 ≤ parameters[i] ≤ 1000. + +[output] array.string + +[JavaScript (ES6)] Syntax Tips + +// Prints help message to the console +// Returns a string +function helloWorld(name) { + console.log("This prints to the console when you Run Tests"); + return "Hello, " + name; +} diff --git a/challenges/shortestString/shortestString.js b/challenges/shortestString/shortestString.js index 5fbc8b73..83bfbbd7 100644 --- a/challenges/shortestString/shortestString.js +++ b/challenges/shortestString/shortestString.js @@ -1,3 +1,6 @@ +/* eslint-disable */ +// TODO: FINISH AND ENABLE LINTING + // remove by finding section of length k with // section of K elements with X property // what is that property? diff --git a/helpers/generateSolution.js b/helpers/generateSolution.js index 30151046..acdbb250 100644 --- a/helpers/generateSolution.js +++ b/helpers/generateSolution.js @@ -4,7 +4,7 @@ const fs = require('fs'); const directory = 'challenges'; -const solutionName = 'shortestString'; +const solutionName = 'playlistRefactor'; const spec = `${solutionName} Spec go here!`; const notes = `${solutionName} Notes go here!`; From 263ea66ba538b81bf7522dbe06c61d4e709c3a9b Mon Sep 17 00:00:00 2001 From: Chris McDermut Date: Fri, 15 May 2020 17:46:11 -0700 Subject: [PATCH 2/6] saving opSe work --- challenges/playlistRefactor/playlistRefactor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenges/playlistRefactor/playlistRefactor.js b/challenges/playlistRefactor/playlistRefactor.js index 03ea41f6..7442a138 100644 --- a/challenges/playlistRefactor/playlistRefactor.js +++ b/challenges/playlistRefactor/playlistRefactor.js @@ -2,4 +2,4 @@ function playlistRefactor(input) { } -module.exports = playlistRefactor +module.exports = playlistRefactor; From 7582bc66136a7066406c0550b8427b135076575f Mon Sep 17 00:00:00 2001 From: Chris McDermut Date: Mon, 7 Dec 2020 15:37:52 -0700 Subject: [PATCH 3/6] saving work --- challenges/bookingManagement/BookManager.js | 48 +++ .../bookingManagement/bookingManagement.js | 64 ---- .../bookingManagement.test.js | 214 ++++++----- .../playlistRefactor/playlistRefactor.js | 2 +- .../playlistRefactor/playlistRefactor.test.js | 357 +++++------------- .../playlistRefactor/playlistRefactorNotes.md | 146 +++++++ 6 files changed, 428 insertions(+), 403 deletions(-) create mode 100644 challenges/bookingManagement/BookManager.js delete mode 100644 challenges/bookingManagement/bookingManagement.js diff --git a/challenges/bookingManagement/BookManager.js b/challenges/bookingManagement/BookManager.js new file mode 100644 index 00000000..8eed0279 --- /dev/null +++ b/challenges/bookingManagement/BookManager.js @@ -0,0 +1,48 @@ +class BookManager { + constructor() { + this.books = []; + } + + createBook(idArg, title) { + // TODO: return false if the book id already exists + const id = parseInt(idArg, 10); + const book = {}; + book.id = id; + book.title = title; + this.books = [...this.books, book]; + return true; + } + + updateBook(idArg, title) { + // TODO: return false if the book doesn't exist + + const id = parseInt(idArg, 10); + this.books = this.books.filter(() => ({ + id, + title, + })); + return true; + } + + deleteBook(idArg) { + // TODO: return false if the book doesn't exist + + const id = parseInt(idArg, 10); + let foundBook = this.books.find((book) => book.id === id); + console.log('foundBook'); + console.log(foundBook); + // delete book; + foundBook = null; + return true; + } + + findBookById(id) { + return this.books.find((book) => book.id === parseInt(id, 10)); + } + + findBookByTitle(title) { + return this.books.find((book) => book.title === title); + } +} + +module.exports = BookManager; diff --git a/challenges/bookingManagement/bookingManagement.js b/challenges/bookingManagement/bookingManagement.js deleted file mode 100644 index 4e29572f..00000000 --- a/challenges/bookingManagement/bookingManagement.js +++ /dev/null @@ -1,64 +0,0 @@ -function BookManager() { - this.books = []; - - this.createBook = function (id, title) { - // TODO: return false if the book id already exists - id = parseInt(id); - let book = new Object(); - book.id = id; - book.title = title; - this.books = [...this.books, book]; - return true; - }; - - this.updateBook = function (id, title) { - // TODO: return false if the book doesn't exist - - id = parseInt(id); - this.books = this.books.filter(book => { - return { - id: id, - title: title - }; - }); - return true; - }; - - this.deleteBook = function (id) { - // TODO: return false if the book doesn't exist - - id = parseInt(id); - const book = this.books.find(book => book.id === id); - delete book; - return true; - }; - - this.findBookById = function (id) { - return this.books.find(book => book.id === parseInt(id)); - }; - - this.findBookByTitle = function (title) { - return this.books.find(book => book.title === title); - }; -} - -// Do NOT edit the code below this comment. -// You should be able to complete this test without editing below this comment. - -const bookManager = new BookManager(); - -function bookManagementRefactor(operations) { - // Calls corresponding methods of bookManager based on the input - return operations.map(operation => { - const [methodName, ...params] = operation; - let result = bookManager[methodName].call(bookManager, ...params); - return result === undefined ? "null" : JSON.stringify(result); - }); -} - - -function bookingManagement(input) { - -} - -module.exports = bookingManagement diff --git a/challenges/bookingManagement/bookingManagement.test.js b/challenges/bookingManagement/bookingManagement.test.js index 14793b0a..b4d466ac 100644 --- a/challenges/bookingManagement/bookingManagement.test.js +++ b/challenges/bookingManagement/bookingManagement.test.js @@ -1,93 +1,137 @@ -const bookingManagement = require('./bookingManagement'); +const BookManager = require('./BookManager'); -const testOne = { - input: '', - output: '', -}; +// Do NOT edit the code below this comment. +// You should be able to complete this test without editing below this comment. + +const bookManager = new BookManager(); + +function bookManagementRefactor(operations) { + // Calls corresponding methods of bookManager based on the input + return operations.map((operation) => { + const [methodName, ...params] = operation; + const result = bookManager[methodName].call(bookManager, ...params); + return result === undefined ? 'null' : JSON.stringify(result); + }); +} describe('bookingManagement Test', () => { test('testOne', () => { - const result = bookingManagement(testOne.input); + const testOne = { + input: [['createBook', '10', 'Book_10'], + ['createBook', '10', 'Book_10'], + ['updateBook', '10', 'New_Book_10'], + ['deleteBook', '9'], + ['findBookById', '9'], + ['findBookById', '10'], + ['findBookByTitle', 'Book_10'], + ['findBookByTitle', 'New_Book_10']], + output: ['true', + 'false', + 'true', + 'false', + 'null', + '{"id":10,"title":"New_Book_10"}', + 'null', + '{"id":10,"title":"New_Book_10"}'], + }; + const result = bookManagementRefactor(testOne.input); expect(result).toEqual(testOne.output); }); -}); + test('testOne', () => { + const testOne = { + input: [['createBook', '10', 'Book 10']], + output: ['true'], + }; + + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); + + test('testOne', () => { + const testOne = { + input: [['updateBook', '462', 'Book 462']], + output: ['false'], + }; + + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); + + + test('testOne', () => { + const testOne = { + input: [['createBook', '23', 'The Greeen Book'], + ['createBook', '23', 'The Red Book'], + ['createBook', '22', 'The Green Book'], + ['updateBook', '23', 'The Green Book'], + ['findBookById', '23'], + ['findBookById', '22'], + ['updateBook', '22', 'The Red Book'], + ['findBookByTitle', 'The Red Book'], + ['findBookByTitle', 'The Green Book']], + output: ['true', + 'false', + 'true', + 'true', + '{"id":23,"title":"The Green Book"}', + '{"id":22,"title":"The Green Book"}', + 'true', + '{"id":22,"title":"The Red Book"}', + '{"id":23,"title":"The Green Book"}'], + }; -operations: -[["createBook","10","Book_10"], - ["createBook","10","Book_10"], - ["updateBook","10","New_Book_10"], - ["deleteBook","9"], - ["findBookById","9"], - ["findBookById","10"], - ["findBookByTitle","Book_10"], - ["findBookByTitle","New_Book_10"]] -Expected Output: -["true", - "false", - "true", - "false", - "null", - "{\"id\":10,\"title\":\"New_Book_10\"}", - "null", - "{\"id\":10,\"title\":\"New_Book_10\"}"] - - - -operations: [["createBook","10","Book 10"]] -Expected Output: -["true"] - -operations: [["updateBook","462","Book 462"]] -Expected Output: -["false"] - -Input: -operations: -[["createBook","23","The Greeen Book"], - ["createBook","23","The Red Book"], - ["createBook","22","The Green Book"], - ["updateBook","23","The Green Book"], - ["findBookById","23"], - ["findBookById","22"], - ["updateBook","22","The Red Book"], - ["findBookByTitle","The Red Book"], - ["findBookByTitle","The Green Book"]] -Expected Output: -["true", - "false", - "true", - "true", - "{\"id\":23,\"title\":\"The Green Book\"}", - "{\"id\":22,\"title\":\"The Green Book\"}", - "true", - "{\"id\":22,\"title\":\"The Red Book\"}", - "{\"id\":23,\"title\":\"The Green Book\"}"] -Click the "Run Tests" button to see output and console logs. - -Input: -operations: -[["createBook","733","Book 733"], - ["findBookById","236"]] -Expected Output: -["true", - "null"] -Click the "Run Tests" button to see output and console logs. - -Input: -operations: -[["createBook","733","Book 733"], - ["findBookById","733"]] -Expected Output: -["true", - "{\"id\":733,\"title\":\"Book 733\"}"] - - Input: -operations: -[["createBook","269","Book 269"], - ["updateBook","454","Book 454"], - ["findBookByTitle","Book 269"]] -Expected Output: -["true", - "false", - "{\"id\":269,\"title\":\"Book 269\"}"] + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); + + test('testOne', () => { + const testOne = { + input: [['createBook', '733', 'Book 733'], + ['findBookById', '236']], + output: ['true', + 'null'], + }; + + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); + + test('testOne', () => { + const testOne = { + input: [['createBook', '733', 'Book 733'], + ['findBookById', '236']], + output: ['true', + 'null'], + }; + + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); + + test('testOne', () => { + const testOne = { + input: [['createBook', '733', 'Book 733'], + ['findBookById', '733']], + output: ['true', + '{"id":733,"title":"Book 733"}'], + }; + + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); + + test('testOne', () => { + const testOne = { + input: [['createBook', '269', 'Book 269'], + ['updateBook', '454', 'Book 454'], + ['findBookByTitle', 'Book 269']], + output: ['true', + 'false', + '{"id":269,"title":"Book 269"}'], + }; + + const result = bookManagementRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); +}); diff --git a/challenges/playlistRefactor/playlistRefactor.js b/challenges/playlistRefactor/playlistRefactor.js index 7442a138..be0479a0 100644 --- a/challenges/playlistRefactor/playlistRefactor.js +++ b/challenges/playlistRefactor/playlistRefactor.js @@ -1,4 +1,4 @@ -function playlistRefactor(input) { +function playlistRefactor() { } diff --git a/challenges/playlistRefactor/playlistRefactor.test.js b/challenges/playlistRefactor/playlistRefactor.test.js index ade5acfc..0073d763 100644 --- a/challenges/playlistRefactor/playlistRefactor.test.js +++ b/challenges/playlistRefactor/playlistRefactor.test.js @@ -1,256 +1,107 @@ -const playlistRefactor = require('./playlistRefactor') - -const testOne = { - input: '', - output: '' -} +const playlistRefactor = require('./playlistRefactor'); describe('playlistRefactor Test', () => { - - test('testOne', ()=>{ - let result = playlistRefactor(testOne.input) + test('testOne', () => { + const testOne = { + commands: + ['add', + 'play', + 'get', + 'add', + 'play', + 'play', + 'get', + 'play', + 'get'], + names: + ['I Still Miss Someone', + 'I Still Miss Someone', + '', + 'Toxicity', + 'I Still Miss Someone', + 'I Still Miss Someone', + '', + 'I Still Miss Someone', + ''], + parameters: [1, 751, 0, 584, 1, 824, 0, 220, 0], + Output: + ['[Track(name = I Still Miss Someone, duration = 1, pausedOn = 750)]', + '[Track(name = I Still Miss Someone, duration = 1, pausedOn = 1573), Track(name = Toxicity, duration = 584, pausedOn = 0)]', + '[Track(name = I Still Miss Someone, duration = 1, pausedOn = 1792), Track(name = Toxicity, duration = 584, pausedOn = 0)]'], + ExpectedOutput: + ['[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0)]', + '[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 584, pausedOn = 0)]', + '[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 584, pausedOn = 0)]'], + ConsoleOutput: [ + 'PLAY CALLED FOR TIME', + '751', + 'PLAY CALLED FOR TIME', + '1', + 'PLAY CALLED FOR TIME', + '824', + 'PLAY CALLED FOR TIME', + '220', + ], + }; + const result = playlistRefactor(testOne.input); expect(result).toEqual(testOne.output); - }) - -}) - - -commands: -["add", - "play", - "get", - "add", - "play", - "play", - "get", - "play", - "get"] -names: -["I Still Miss Someone", - "I Still Miss Someone", - "", - "Toxicity", - "I Still Miss Someone", - "I Still Miss Someone", - "", - "I Still Miss Someone", - ""] -parameters: [1, 751, 0, 584, 1, 824, 0, 220, 0] -Output: -["[Track(name = I Still Miss Someone, duration = 1, pausedOn = 750)]", - "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 1573), Track(name = Toxicity, duration = 584, pausedOn = 0)]", - "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 1792), Track(name = Toxicity, duration = 584, pausedOn = 0)]"] -Expected Output: -["[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0)]", - "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 584, pausedOn = 0)]", - "[Track(name = I Still Miss Someone, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 584, pausedOn = 0)]"] -Console Output: -PLAY CALLED FOR TIME -751 -PLAY CALLED FOR TIME -1 -PLAY CALLED FOR TIME -824 -PLAY CALLED FOR TIME -220 - -nput: -commands: -["add", - "add", - "add", - "add", - "get", - "move", - "get", - "move", - "get", - "add", - "add", - "get", - "move", - "get", - "move", - "get"] -names: -["\"Long Gone(From the Bowlin Green)\"", - "Symphony #9 in D minor(\"Choral\"),Op. 125", - "I Walk the Line", - "Jackie Cane", - "", - "Symphony #9 in D minor(\"Choral\"),Op. 125", - "", - "I Walk the Line", - "", - "OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo", - "Toxicity", - "", - "Toxicity", - "", - "Toxicity", - ""] -parameters: [1, 509, 1, 568, 0, 0, 0, 2, 0, 1, 1000, 0, 3, 0, 2, 0] -Output: -["[Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]"] -Expected Output: -["[Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0)]", - "[Track(name = Symphony #9 in D minor(\"Choral\"),Op. 125, duration = 509, pausedOn = 0), Track(name = \"Long Gone(From the Bowlin Green)\", duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0)]"] -Console Output: -Empty - - -//////// - -Time's Up! -The test is now over, and you may not make further changes. -You have one minute to submit your work if you have not done so already. -dataMeans -( -0:00:53 -) -Codewriting - -You are given the files data.json and data.csv in the /root/devops/ directory. - -data.json contains a JSON array of objects with the following format: - -{ - "id": string, - "id2": string, - "key": string, - "created": number, // UNIX timestamp (UTC) in milliseconds - "district": string -} -while data.csv has the following columns - -id,sla,overdue,x,y,type -string,number,number,number,number,number -where id corresponds to id in data.json. - -Find out which day of the week has the lowest mean overdue value, and output it to the console. - -Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. - -Example - -For the following data.json - -[ - {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, - {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, - {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, - {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, - {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, - {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} -] -and data.csv - -id,sla,overdue,x,y,type -4,10.0,-8.98,3105443.57,13832598.28,3.0 -1,14.0,-7.79,3047695.62,13826869.96,3.0 -3,10.0,-8.59,3078170.34,13820368.28,3.0 -2,10.0,-8.98,3105443.57,13832598.28,3.0 -7,14.0,-7.79,3047695.62,13826869.96,3.0 -0,10.0,-8.59,3078170.34,13820368.28,3.0 -the output for this should be: - -Friday -C -[execution time limit] 25 seconds (js) -JavaScript (ES6) -12 -console.log('Hello world'); - -TESTS -Test 1 -Input: -View the setup script -Expected Output: -Friday -C -Click the "Run Tests" button to see output and console logs. -Test 2 -Test 3 -Test 4 -Test 5 -Test 6 -Formatting -Editor Mode -VS Code -Theme -Dark -Tab Size -Auto -Font Size -14px -Auto-brackets -Minimap -Code Completion -Error Highlighting -Hotkeys -CTRL/CMD + Enter -Submit -CTRL/CMD + R -Run -CTRL/CMD + S -Save -0/300 - -resetTrack - -You are given the files data.json and data.csv in the /root/devops/ directory. - -data.json contains a JSON array of objects with the following format: - -{ - "id": string, - "id2": string, - "key": string, - "created": number, // UNIX timestamp (UTC) in milliseconds - "district": string -} -while data.csv has the following columns - -id,sla,overdue,x,y,type -string,number,number,number,number,number -where id corresponds to id in data.json. - -Find out which day of the week has the lowest mean overdue value, and output it to the console. - -Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. - -Example - -For the following data.json - -[ - {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, - {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, - {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, - {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, - {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, - {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} -] -and data.csv - -id,sla,overdue,x,y,type -4,10.0,-8.98,3105443.57,13832598.28,3.0 -1,14.0,-7.79,3047695.62,13826869.96,3.0 -3,10.0,-8.59,3078170.34,13820368.28,3.0 -2,10.0,-8.98,3105443.57,13832598.28,3.0 -7,14.0,-7.79,3047695.62,13826869.96,3.0 -0,10.0,-8.59,3078170.34,13820368.28,3.0 -the output for this should be: - -Friday -C -[execution time limit] 25 seconds (js) + }); + + test('testOne', () => { + const testOne = { + commands: + ['add', + 'add', + 'add', + 'add', + 'get', + 'move', + 'get', + 'move', + 'get', + 'add', + 'add', + 'get', + 'move', + 'get', + 'move', + 'get'], + names: + ['"Long Gone(From the Bowlin Green)"', + 'Symphony #9 in D minor("Choral"),Op. 125', + 'I Walk the Line', + 'Jackie Cane', + '', + 'Symphony #9 in D minor("Choral"),Op. 125', + '', + 'I Walk the Line', + '', + 'OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo', + 'Toxicity', + '', + 'Toxicity', + '', + 'Toxicity', + ''], + parameters: [1, 509, 1, 568, 0, 0, 0, 2, 0, 1, 1000, 0, 3, 0, 2, 0], + Output: + ['[Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]'], + ExpectedOutput: + ['[Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0)]', + '[Track(name = Symphony #9 in D minor("Choral"),Op. 125, duration = 509, pausedOn = 0), Track(name = "Long Gone(From the Bowlin Green)", duration = 1, pausedOn = 0), Track(name = Toxicity, duration = 1000, pausedOn = 0), Track(name = I Walk the Line, duration = 1, pausedOn = 0), Track(name = Jackie Cane, duration = 568, pausedOn = 0), Track(name = OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo, duration = 1, pausedOn = 0)]'], + ConsoleOutput: /* Empty */ + [], + }; + const result = playlistRefactor(testOne.input); + expect(result).toEqual(testOne.output); + }); +}); diff --git a/challenges/playlistRefactor/playlistRefactorNotes.md b/challenges/playlistRefactor/playlistRefactorNotes.md index cdb358bf..3d17df24 100644 --- a/challenges/playlistRefactor/playlistRefactorNotes.md +++ b/challenges/playlistRefactor/playlistRefactorNotes.md @@ -332,3 +332,149 @@ function playlistRefactoring(commands, names, parameters) { return result; } + + + + +//////// +dataMeans +( +0:00:53 +) +Codewriting + +You are given the files data.json and data.csv in the /root/devops/ directory. + +data.json contains a JSON array of objects with the following format: + +{ + "id": string, + "id2": string, + "key": string, + "created": number, // UNIX timestamp (UTC) in milliseconds + "district": string +} +while data.csv has the following columns + +id,sla,overdue,x,y,type +string,number,number,number,number,number +where id corresponds to id in data.json. + +Find out which day of the week has the lowest mean overdue value, and output it to the console. + +Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. + +Example + +For the following data.json + +[ + {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, + {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, + {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, + {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, + {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, + {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} +] +and data.csv + +id,sla,overdue,x,y,type +4,10.0,-8.98,3105443.57,13832598.28,3.0 +1,14.0,-7.79,3047695.62,13826869.96,3.0 +3,10.0,-8.59,3078170.34,13820368.28,3.0 +2,10.0,-8.98,3105443.57,13832598.28,3.0 +7,14.0,-7.79,3047695.62,13826869.96,3.0 +0,10.0,-8.59,3078170.34,13820368.28,3.0 +the output for this should be: + +Friday +C +[execution time limit] 25 seconds (js) +JavaScript (ES6) +12 +console.log('Hello world'); + +TESTS +Test 1 +Input: +View the setup script +Expected Output: +Friday +C +Click the "Run Tests" button to see output and console logs. +Test 2 +Test 3 +Test 4 +Test 5 +Test 6 +Formatting +Editor Mode +VS Code +Theme +Dark +Tab Size +Auto +Font Size +14px +Auto-brackets +Minimap +Code Completion +Error Highlighting +Hotkeys +CTRL/CMD + Enter +Submit +CTRL/CMD + R +Run +CTRL/CMD + S +Save +0/300 + +resetTrack + +You are given the files data.json and data.csv in the /root/devops/ directory. + +data.json contains a JSON array of objects with the following format: + +{ + "id": string, + "id2": string, + "key": string, + "created": number, // UNIX timestamp (UTC) in milliseconds + "district": string +} +while data.csv has the following columns + +id,sla,overdue,x,y,type +string,number,number,number,number,number +where id corresponds to id in data.json. + +Find out which day of the week has the lowest mean overdue value, and output it to the console. + +Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. + +Example + +For the following data.json + +[ + {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, + {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, + {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, + {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, + {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, + {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} +] +and data.csv + +id,sla,overdue,x,y,type +4,10.0,-8.98,3105443.57,13832598.28,3.0 +1,14.0,-7.79,3047695.62,13826869.96,3.0 +3,10.0,-8.59,3078170.34,13820368.28,3.0 +2,10.0,-8.98,3105443.57,13832598.28,3.0 +7,14.0,-7.79,3047695.62,13826869.96,3.0 +0,10.0,-8.59,3078170.34,13820368.28,3.0 +the output for this should be: + +Friday +C +[execution time limit] 25 seconds (js) From 540728176eebcadb882fde6629ac488edea22239 Mon Sep 17 00:00:00 2001 From: Chris McDermut Date: Tue, 8 Dec 2020 23:41:51 -0700 Subject: [PATCH 4/6] trying out an object --- challenges/bookingManagement/BookManager.js | 69 +++++++++++++------ .../bookingManagement.test.js | 26 +++---- .../bookingManagementSpec.md | 2 + 3 files changed, 65 insertions(+), 32 deletions(-) diff --git a/challenges/bookingManagement/BookManager.js b/challenges/bookingManagement/BookManager.js index 8eed0279..46b78ee7 100644 --- a/challenges/bookingManagement/BookManager.js +++ b/challenges/bookingManagement/BookManager.js @@ -1,47 +1,76 @@ class BookManager { constructor() { - this.books = []; + // this.books = []; + this.books = {}; } createBook(idArg, title) { // TODO: return false if the book id already exists const id = parseInt(idArg, 10); - const book = {}; - book.id = id; - book.title = title; - this.books = [...this.books, book]; - return true; + // const foundBook = this.books.find((book) => book.id === id); + if (!this.books[id]) { + const book = {}; + book.id = id; + book.title = title; + // this.books = [...this.books, book]; + this.books[id] = book; + return true; + } + return false; } updateBook(idArg, title) { // TODO: return false if the book doesn't exist - const id = parseInt(idArg, 10); - this.books = this.books.filter(() => ({ - id, - title, - })); + // const foundBook = this.books.find((book) => book.id === id); + if (!this.books[id]) { + return false; + } + const book = {}; + book.id = id; + book.title = title; + + this.books[id] = book; + + // = this.books.filter(() => ({ + // id, + // title, + // }) + + // ); + return true; } deleteBook(idArg) { // TODO: return false if the book doesn't exist - const id = parseInt(idArg, 10); - let foundBook = this.books.find((book) => book.id === id); - console.log('foundBook'); - console.log(foundBook); - // delete book; - foundBook = null; + // let foundBook = this.books.find((book) => book.id === id); + if (!this.books[id]) { + return false; + } + delete this.books[id]; + // // let foundBook = this.books.find((book) => book.id === id); + // console.log('foundBook'); + // console.log(foundBook); + // // delete book; + // foundBook = null; return true; } - findBookById(id) { - return this.books.find((book) => book.id === parseInt(id, 10)); + findBookById(idArg) { + const id = parseInt(idArg, 10); + // const foundBook = this.books.find((book) => book.id === id); + // return foundBook || null; + // return this.books.find((book) => book.id === id); + return this.books[id] ? this.books[id] : null; } findBookByTitle(title) { - return this.books.find((book) => book.title === title); + // const foundBook = this.books.find((book) => book.title === title); + // return foundBook || null; + // return this.books.find((book) => book.title === title); + return this.books[title] ? this.books[title] : null; } } diff --git a/challenges/bookingManagement/bookingManagement.test.js b/challenges/bookingManagement/bookingManagement.test.js index b4d466ac..0c5e3141 100644 --- a/challenges/bookingManagement/bookingManagement.test.js +++ b/challenges/bookingManagement/bookingManagement.test.js @@ -10,7 +10,7 @@ function bookManagementRefactor(operations) { return operations.map((operation) => { const [methodName, ...params] = operation; const result = bookManager[methodName].call(bookManager, ...params); - return result === undefined ? 'null' : JSON.stringify(result); + return result === undefined ? null : JSON.stringify(result); }); } @@ -29,16 +29,18 @@ describe('bookingManagement Test', () => { 'false', 'true', 'false', - 'null', + null, '{"id":10,"title":"New_Book_10"}', - 'null', + null, '{"id":10,"title":"New_Book_10"}'], }; const result = bookManagementRefactor(testOne.input); + console.log('result'); + console.log(result); expect(result).toEqual(testOne.output); }); - test('testOne', () => { + test('testTwo', () => { const testOne = { input: [['createBook', '10', 'Book 10']], output: ['true'], @@ -48,7 +50,7 @@ describe('bookingManagement Test', () => { expect(result).toEqual(testOne.output); }); - test('testOne', () => { + test('testThree', () => { const testOne = { input: [['updateBook', '462', 'Book 462']], output: ['false'], @@ -59,7 +61,7 @@ describe('bookingManagement Test', () => { }); - test('testOne', () => { + test('testFour', () => { const testOne = { input: [['createBook', '23', 'The Greeen Book'], ['createBook', '23', 'The Red Book'], @@ -85,31 +87,31 @@ describe('bookingManagement Test', () => { expect(result).toEqual(testOne.output); }); - test('testOne', () => { + test('testFive', () => { const testOne = { input: [['createBook', '733', 'Book 733'], ['findBookById', '236']], output: ['true', - 'null'], + null], }; const result = bookManagementRefactor(testOne.input); expect(result).toEqual(testOne.output); }); - test('testOne', () => { + test('testSix', () => { const testOne = { input: [['createBook', '733', 'Book 733'], ['findBookById', '236']], output: ['true', - 'null'], + null], }; const result = bookManagementRefactor(testOne.input); expect(result).toEqual(testOne.output); }); - test('testOne', () => { + test('testSeven', () => { const testOne = { input: [['createBook', '733', 'Book 733'], ['findBookById', '733']], @@ -121,7 +123,7 @@ describe('bookingManagement Test', () => { expect(result).toEqual(testOne.output); }); - test('testOne', () => { + test('testEight', () => { const testOne = { input: [['createBook', '269', 'Book 269'], ['updateBook', '454', 'Book 454'], diff --git a/challenges/bookingManagement/bookingManagementSpec.md b/challenges/bookingManagement/bookingManagementSpec.md index 41eac767..5af8eb38 100644 --- a/challenges/bookingManagement/bookingManagementSpec.md +++ b/challenges/bookingManagement/bookingManagementSpec.md @@ -18,6 +18,8 @@ Example For operations = [["createBook", "10", "Book_10"], ["createBook", "10", "Book_10"], ["updateBook", "10", "New_Book_10"], ["deleteBook", "9"],["findBookById", "9"], ["findBookById", "10"], ["findBookByTitle", "Book_10"], ["findBookByTitle", "New_Book_10"]], the output should be bookManagementRefactor(operations) = ["true", "false", "true", "false", "null", "{"id":10,"title":"New_Book_10"}", "null", "{"id":10,"title":"New_Book_10"}"]. +//////////////////////////NOTHING IMPORTANT + Input/Output [execution time limit] 4 seconds (js) From 960f11cb94783a95132034f95934bcadf4e8dd1b Mon Sep 17 00:00:00 2001 From: Chris McDermut Date: Wed, 9 Dec 2020 18:58:07 -0700 Subject: [PATCH 5/6] book manager tests working --- challenges/bookingManagement/BookManager.js | 56 +++++--------- .../bookingManagement/BookManagerMap.js | 76 +++++++++++++++++++ .../bookingManagement.test.js | 28 +++++-- 3 files changed, 119 insertions(+), 41 deletions(-) create mode 100644 challenges/bookingManagement/BookManagerMap.js diff --git a/challenges/bookingManagement/BookManager.js b/challenges/bookingManagement/BookManager.js index 46b78ee7..543a3665 100644 --- a/challenges/bookingManagement/BookManager.js +++ b/challenges/bookingManagement/BookManager.js @@ -1,76 +1,60 @@ class BookManager { constructor() { - // this.books = []; - this.books = {}; + this.books = []; } createBook(idArg, title) { - // TODO: return false if the book id already exists const id = parseInt(idArg, 10); - // const foundBook = this.books.find((book) => book.id === id); - if (!this.books[id]) { + const foundBook = this.books.find((book) => book.id === id); + if (!foundBook) { const book = {}; book.id = id; book.title = title; - // this.books = [...this.books, book]; - this.books[id] = book; + this.books = [...this.books, book]; return true; } return false; } updateBook(idArg, title) { - // TODO: return false if the book doesn't exist const id = parseInt(idArg, 10); - // const foundBook = this.books.find((book) => book.id === id); - if (!this.books[id]) { + const foundBook = this.books.find((book) => book.id === id); + if (!foundBook) { return false; } + const foundBookIndex = this.books.indexOf(foundBook); + const book = {}; book.id = id; book.title = title; - this.books[id] = book; - - // = this.books.filter(() => ({ - // id, - // title, - // }) - - // ); - + const currentBookList = this.books; + currentBookList.splice(foundBookIndex, 1, book); + this.books = [...currentBookList]; return true; } deleteBook(idArg) { - // TODO: return false if the book doesn't exist const id = parseInt(idArg, 10); - // let foundBook = this.books.find((book) => book.id === id); - if (!this.books[id]) { + const foundBook = this.books.find((book) => book.id === id); + const foundBookIndex = this.books.indexOf(foundBook); + if (!foundBook) { return false; } - delete this.books[id]; - // // let foundBook = this.books.find((book) => book.id === id); - // console.log('foundBook'); - // console.log(foundBook); - // // delete book; - // foundBook = null; + const newBookArray = this.books.splice(foundBookIndex, 1); + this.books = newBookArray; return true; } findBookById(idArg) { const id = parseInt(idArg, 10); - // const foundBook = this.books.find((book) => book.id === id); - // return foundBook || null; - // return this.books.find((book) => book.id === id); - return this.books[id] ? this.books[id] : null; + const foundBook = this.books.find((book) => book.id === id); + return foundBook || null; } findBookByTitle(title) { - // const foundBook = this.books.find((book) => book.title === title); - // return foundBook || null; - // return this.books.find((book) => book.title === title); - return this.books[title] ? this.books[title] : null; + const foundBook = this.books.find((book) => book.title === title); + return foundBook || null; } } diff --git a/challenges/bookingManagement/BookManagerMap.js b/challenges/bookingManagement/BookManagerMap.js new file mode 100644 index 00000000..2e80c247 --- /dev/null +++ b/challenges/bookingManagement/BookManagerMap.js @@ -0,0 +1,76 @@ +class BookManager { + constructor() { + this.books = {}; + } + + createBook(idArg, title) { + // TODO: return false if the book id already exists + const id = parseInt(idArg, 10); + // const foundBook = this.books.find((book) => book.id === id); + if (!this.books[id]) { + const book = {}; + book.id = id; + book.title = title; + // this.books = [...this.books, book]; + this.books[id] = book; + return true; + } + return false; + } + + updateBook(idArg, title) { + // TODO: return false if the book doesn't exist + const id = parseInt(idArg, 10); + // const foundBook = this.books.find((book) => book.id === id); + if (!this.books[id]) { + return false; + } + const book = {}; + book.id = id; + book.title = title; + + this.books[id] = book; + + // = this.books.filter(() => ({ + // id, + // title, + // }) + + // ); + + return true; + } + + deleteBook(idArg) { + // TODO: return false if the book doesn't exist + const id = parseInt(idArg, 10); + // let foundBook = this.books.find((book) => book.id === id); + if (!this.books[id]) { + return false; + } + delete this.books[id]; + // // let foundBook = this.books.find((book) => book.id === id); + // console.log('foundBook'); + // console.log(foundBook); + // // delete book; + // foundBook = null; + return true; + } + + findBookById(idArg) { + const id = parseInt(idArg, 10); + // const foundBook = this.books.find((book) => book.id === id); + // return foundBook || null; + // return this.books.find((book) => book.id === id); + return this.books[id] ? this.books[id] : null; + } + + findBookByTitle(title) { + // const foundBook = this.books.find((book) => book.title === title); + // return foundBook || null; + // return this.books.find((book) => book.title === title); + return this.books[title] ? this.books[title] : null; + } +} + +module.exports = BookManager; diff --git a/challenges/bookingManagement/bookingManagement.test.js b/challenges/bookingManagement/bookingManagement.test.js index 0c5e3141..9434c82e 100644 --- a/challenges/bookingManagement/bookingManagement.test.js +++ b/challenges/bookingManagement/bookingManagement.test.js @@ -3,17 +3,37 @@ const BookManager = require('./BookManager'); // Do NOT edit the code below this comment. // You should be able to complete this test without editing below this comment. -const bookManager = new BookManager(); - function bookManagementRefactor(operations) { + const bookManager = new BookManager(); // Calls corresponding methods of bookManager based on the input return operations.map((operation) => { const [methodName, ...params] = operation; const result = bookManager[methodName].call(bookManager, ...params); - return result === undefined ? null : JSON.stringify(result); + return (result === undefined || result === null) ? null : JSON.stringify(result); }); } +describe('bookingManagement createBook Test', () => { + test('testOne', () => { + const bookManager = new BookManager(); + bookManager.createBook('10', 'Book_10'); + const result = bookManager.books; + const answer = [{ id: 10, title: 'Book_10' }]; + expect(result).toEqual(answer); + }); +}); + +describe('bookingManagement updateBook Test', () => { + test('testOne', () => { + const bookManager = new BookManager(); + bookManager.createBook('10', 'Book_10'); + bookManager.updateBook('10', 'Updated_Book_10'); + const result = bookManager.books; + const answer = [{ id: 10, title: 'Updated_Book_10' }]; + expect(result).toEqual(answer); + }); +}); + describe('bookingManagement Test', () => { test('testOne', () => { const testOne = { @@ -35,8 +55,6 @@ describe('bookingManagement Test', () => { '{"id":10,"title":"New_Book_10"}'], }; const result = bookManagementRefactor(testOne.input); - console.log('result'); - console.log(result); expect(result).toEqual(testOne.output); }); From 042cb60893960bc9c65cf7d0d135ae7d39f7d028 Mon Sep 17 00:00:00 2001 From: Chris McDermut Date: Wed, 9 Dec 2020 19:10:36 -0700 Subject: [PATCH 6/6] track playlist organizing --- .../bookingManagement/BookManagerMap.js | 76 --------- challenges/dataWork/dataWork.js | 5 + challenges/dataWork/dataWork.test.js | 13 ++ challenges/dataWork/dataWorkNotes.md | 143 +++++++++++++++++ challenges/dataWork/dataWorkSpec.md | 1 + .../playlistRefactor/playlistRefactor.js | 124 +++++++++++++++ .../playlistRefactor/playlistRefactorNotes.md | 146 ------------------ helpers/generateBoilerPlate.js | 2 +- 8 files changed, 287 insertions(+), 223 deletions(-) delete mode 100644 challenges/bookingManagement/BookManagerMap.js create mode 100644 challenges/dataWork/dataWork.js create mode 100644 challenges/dataWork/dataWork.test.js create mode 100644 challenges/dataWork/dataWorkNotes.md create mode 100644 challenges/dataWork/dataWorkSpec.md diff --git a/challenges/bookingManagement/BookManagerMap.js b/challenges/bookingManagement/BookManagerMap.js deleted file mode 100644 index 2e80c247..00000000 --- a/challenges/bookingManagement/BookManagerMap.js +++ /dev/null @@ -1,76 +0,0 @@ -class BookManager { - constructor() { - this.books = {}; - } - - createBook(idArg, title) { - // TODO: return false if the book id already exists - const id = parseInt(idArg, 10); - // const foundBook = this.books.find((book) => book.id === id); - if (!this.books[id]) { - const book = {}; - book.id = id; - book.title = title; - // this.books = [...this.books, book]; - this.books[id] = book; - return true; - } - return false; - } - - updateBook(idArg, title) { - // TODO: return false if the book doesn't exist - const id = parseInt(idArg, 10); - // const foundBook = this.books.find((book) => book.id === id); - if (!this.books[id]) { - return false; - } - const book = {}; - book.id = id; - book.title = title; - - this.books[id] = book; - - // = this.books.filter(() => ({ - // id, - // title, - // }) - - // ); - - return true; - } - - deleteBook(idArg) { - // TODO: return false if the book doesn't exist - const id = parseInt(idArg, 10); - // let foundBook = this.books.find((book) => book.id === id); - if (!this.books[id]) { - return false; - } - delete this.books[id]; - // // let foundBook = this.books.find((book) => book.id === id); - // console.log('foundBook'); - // console.log(foundBook); - // // delete book; - // foundBook = null; - return true; - } - - findBookById(idArg) { - const id = parseInt(idArg, 10); - // const foundBook = this.books.find((book) => book.id === id); - // return foundBook || null; - // return this.books.find((book) => book.id === id); - return this.books[id] ? this.books[id] : null; - } - - findBookByTitle(title) { - // const foundBook = this.books.find((book) => book.title === title); - // return foundBook || null; - // return this.books.find((book) => book.title === title); - return this.books[title] ? this.books[title] : null; - } -} - -module.exports = BookManager; diff --git a/challenges/dataWork/dataWork.js b/challenges/dataWork/dataWork.js new file mode 100644 index 00000000..32f1cae5 --- /dev/null +++ b/challenges/dataWork/dataWork.js @@ -0,0 +1,5 @@ +function dataWork(input) { + +} + +module.exports = dataWork; diff --git a/challenges/dataWork/dataWork.test.js b/challenges/dataWork/dataWork.test.js new file mode 100644 index 00000000..e74cbf0c --- /dev/null +++ b/challenges/dataWork/dataWork.test.js @@ -0,0 +1,13 @@ +const dataWork = require('./dataWork'); + +const testOne = { + input: '', + output: '', +}; + +describe('dataWork Test', () => { + test('testOne', () => { + const result = dataWork(testOne.input); + expect(result).toEqual(testOne.output); + }); +}); diff --git a/challenges/dataWork/dataWorkNotes.md b/challenges/dataWork/dataWorkNotes.md new file mode 100644 index 00000000..af310136 --- /dev/null +++ b/challenges/dataWork/dataWorkNotes.md @@ -0,0 +1,143 @@ +dataWork Notes go here! +//////// +dataMeans +( +0:00:53 +) +Codewriting + +You are given the files data.json and data.csv in the /root/devops/ directory. + +data.json contains a JSON array of objects with the following format: + +{ + "id": string, + "id2": string, + "key": string, + "created": number, // UNIX timestamp (UTC) in milliseconds + "district": string +} +while data.csv has the following columns + +id,sla,overdue,x,y,type +string,number,number,number,number,number +where id corresponds to id in data.json. + +Find out which day of the week has the lowest mean overdue value, and output it to the console. + +Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. + +Example + +For the following data.json + +[ + {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, + {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, + {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, + {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, + {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, + {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} +] +and data.csv + +id,sla,overdue,x,y,type +4,10.0,-8.98,3105443.57,13832598.28,3.0 +1,14.0,-7.79,3047695.62,13826869.96,3.0 +3,10.0,-8.59,3078170.34,13820368.28,3.0 +2,10.0,-8.98,3105443.57,13832598.28,3.0 +7,14.0,-7.79,3047695.62,13826869.96,3.0 +0,10.0,-8.59,3078170.34,13820368.28,3.0 +the output for this should be: + +Friday +C +[execution time limit] 25 seconds (js) +JavaScript (ES6) +12 +console.log('Hello world'); + +TESTS +Test 1 +Input: +View the setup script +Expected Output: +Friday +C +Click the "Run Tests" button to see output and console logs. +Test 2 +Test 3 +Test 4 +Test 5 +Test 6 +Formatting +Editor Mode +VS Code +Theme +Dark +Tab Size +Auto +Font Size +14px +Auto-brackets +Minimap +Code Completion +Error Highlighting +Hotkeys +CTRL/CMD + Enter +Submit +CTRL/CMD + R +Run +CTRL/CMD + S +Save +0/300 + +resetTrack + +You are given the files data.json and data.csv in the /root/devops/ directory. + +data.json contains a JSON array of objects with the following format: + +{ + "id": string, + "id2": string, + "key": string, + "created": number, // UNIX timestamp (UTC) in milliseconds + "district": string +} +while data.csv has the following columns + +id,sla,overdue,x,y,type +string,number,number,number,number,number +where id corresponds to id in data.json. + +Find out which day of the week has the lowest mean overdue value, and output it to the console. + +Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. + +Example + +For the following data.json + +[ + {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, + {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, + {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, + {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, + {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, + {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} +] +and data.csv + +id,sla,overdue,x,y,type +4,10.0,-8.98,3105443.57,13832598.28,3.0 +1,14.0,-7.79,3047695.62,13826869.96,3.0 +3,10.0,-8.59,3078170.34,13820368.28,3.0 +2,10.0,-8.98,3105443.57,13832598.28,3.0 +7,14.0,-7.79,3047695.62,13826869.96,3.0 +0,10.0,-8.59,3078170.34,13820368.28,3.0 +the output for this should be: + +Friday +C +[execution time limit] 25 seconds (js) diff --git a/challenges/dataWork/dataWorkSpec.md b/challenges/dataWork/dataWorkSpec.md new file mode 100644 index 00000000..9101a8d9 --- /dev/null +++ b/challenges/dataWork/dataWorkSpec.md @@ -0,0 +1 @@ +dataWork Spec goes here! \ No newline at end of file diff --git a/challenges/playlistRefactor/playlistRefactor.js b/challenges/playlistRefactor/playlistRefactor.js index be0479a0..5f1abd7b 100644 --- a/challenges/playlistRefactor/playlistRefactor.js +++ b/challenges/playlistRefactor/playlistRefactor.js @@ -2,4 +2,128 @@ function playlistRefactor() { } +class Track { + constructor(name, duration) { + this.name = name; + this.duration = duration; + this.pausedOn = 0; + } + + play(time) { + console.log('PLAY CALLED FOR TIME'); + console.log(time); + // TODO: implement this method + // console.log('this.pausedOn') + // console.log(this.pausedOn) + // console.log('time') + // console.log(time) + if ((this.pausedOn + time) < this.duration) { + this.pausedOn += time; + } else { + this.pausedOn = ((this.pausedOn + time) - this.duration); + } + // console.log('AFTER this.pausedOn') + // console.log(this.pausedOn) + } + + reset() { + this.pausedOn = 0; + } + + toString() { + return `Track(name = ${this.name}, duration = ${this.duration}, pausedOn = ${this.pausedOn})`; + } +} + +class Playlist { + constructor() { + this.trackList = []; + } + + addTrack(name, duration) { + const newTrack = new Track(name, duration); + this.trackList.push(newTrack); + } + + deleteTrack(name) { + this.trackList = this.trackList.filter((track) => track.name !== name); + } + + playTrack(name, time) { + this.trackList.forEach((track, i) => { + if (track.name === name) { + track.play(time); + } + }); + } + + resetTrack(name) { + // TODO: implement this method + if (name) { + this.trackList.forEach((track, i) => { + if (track.name === name) { + this.trackList[i].reset(); + } + }); + } else { + this.trackList.forEach((track, i) => { + track.reset(); + }); + } + } + + trackIndexByName(name) { + // TODO: implement this method + return findWithAttr(this.trackList, 'name', name); + } + + moveTrack(name, toIndex) { + const index = this.trackIndexByName(name); + if (index === toIndex) { + return; + } + this.trackList.splice(toIndex, 0, this.trackList[index]); + } + + toString() { + return `[${this.trackList.map((track) => track.toString()).join(', ')}]`; + } +} + +function findWithAttr(array, attr, value) { + for (let i = 0; i < array.length; i += 1) { + if (array[i][attr] === value) { + return i; + } + } + return -1; +} + +function playlistRefactoring(commands, names, parameters) { + const playlist = new Playlist(); + const result = []; + + for (let i = 0; i < commands.length; i++) { + if (commands[i] === 'add') { + playlist.addTrack(names[i], parameters[i]); + } else if (commands[i] === 'delete') { + playlist.deleteTrack(names[i]); + } else if (commands[i] === 'play') { + playlist.playTrack(names[i], parameters[i]); + } else if (commands[i] === 'reset') { + if (names[i] === '') { + playlist.resetTrack(); + } else { + playlist.resetTrack(names[i]); + } + } else if (commands[i] === 'move') { + playlist.moveTrack(names[i], parameters[i]); + } else { // commands[i] === 'get' + result.push(playlist.toString()); + } + } + + return result; +} + module.exports = playlistRefactor; diff --git a/challenges/playlistRefactor/playlistRefactorNotes.md b/challenges/playlistRefactor/playlistRefactorNotes.md index 3d17df24..cdb358bf 100644 --- a/challenges/playlistRefactor/playlistRefactorNotes.md +++ b/challenges/playlistRefactor/playlistRefactorNotes.md @@ -332,149 +332,3 @@ function playlistRefactoring(commands, names, parameters) { return result; } - - - - -//////// -dataMeans -( -0:00:53 -) -Codewriting - -You are given the files data.json and data.csv in the /root/devops/ directory. - -data.json contains a JSON array of objects with the following format: - -{ - "id": string, - "id2": string, - "key": string, - "created": number, // UNIX timestamp (UTC) in milliseconds - "district": string -} -while data.csv has the following columns - -id,sla,overdue,x,y,type -string,number,number,number,number,number -where id corresponds to id in data.json. - -Find out which day of the week has the lowest mean overdue value, and output it to the console. - -Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. - -Example - -For the following data.json - -[ - {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, - {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, - {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, - {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, - {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, - {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} -] -and data.csv - -id,sla,overdue,x,y,type -4,10.0,-8.98,3105443.57,13832598.28,3.0 -1,14.0,-7.79,3047695.62,13826869.96,3.0 -3,10.0,-8.59,3078170.34,13820368.28,3.0 -2,10.0,-8.98,3105443.57,13832598.28,3.0 -7,14.0,-7.79,3047695.62,13826869.96,3.0 -0,10.0,-8.59,3078170.34,13820368.28,3.0 -the output for this should be: - -Friday -C -[execution time limit] 25 seconds (js) -JavaScript (ES6) -12 -console.log('Hello world'); - -TESTS -Test 1 -Input: -View the setup script -Expected Output: -Friday -C -Click the "Run Tests" button to see output and console logs. -Test 2 -Test 3 -Test 4 -Test 5 -Test 6 -Formatting -Editor Mode -VS Code -Theme -Dark -Tab Size -Auto -Font Size -14px -Auto-brackets -Minimap -Code Completion -Error Highlighting -Hotkeys -CTRL/CMD + Enter -Submit -CTRL/CMD + R -Run -CTRL/CMD + S -Save -0/300 - -resetTrack - -You are given the files data.json and data.csv in the /root/devops/ directory. - -data.json contains a JSON array of objects with the following format: - -{ - "id": string, - "id2": string, - "key": string, - "created": number, // UNIX timestamp (UTC) in milliseconds - "district": string -} -while data.csv has the following columns - -id,sla,overdue,x,y,type -string,number,number,number,number,number -where id corresponds to id in data.json. - -Find out which day of the week has the lowest mean overdue value, and output it to the console. - -Next, determine which district's mean location (x and y coordinates) is closest to the mean location of all data, ignoring data from district Unknown. Print this district's name on the next line. - -Example - -For the following data.json - -[ - {"id": "1", "id2": "01", "key": "A", "created": 1518066000000, "district": "A"}, - {"id": "2", "id2": "02", "key": "B", "created": 1518066010000, "district": "Z"}, - {"id": "3", "id2": "03", "key": "C", "created": 1358517124000, "district": "C"}, - {"id": "4", "id2": "15", "key": "D", "created": 1358517113000, "district": "A"}, - {"id": "0", "id2": "10", "key": "D", "created": 1358517114000, "district": "Z"}, - {"id": "7", "id2": "20", "key": "Z", "created": 1517793152000, "district": "F"} -] -and data.csv - -id,sla,overdue,x,y,type -4,10.0,-8.98,3105443.57,13832598.28,3.0 -1,14.0,-7.79,3047695.62,13826869.96,3.0 -3,10.0,-8.59,3078170.34,13820368.28,3.0 -2,10.0,-8.98,3105443.57,13832598.28,3.0 -7,14.0,-7.79,3047695.62,13826869.96,3.0 -0,10.0,-8.59,3078170.34,13820368.28,3.0 -the output for this should be: - -Friday -C -[execution time limit] 25 seconds (js) diff --git a/helpers/generateBoilerPlate.js b/helpers/generateBoilerPlate.js index 3d9a776f..54057648 100644 --- a/helpers/generateBoilerPlate.js +++ b/helpers/generateBoilerPlate.js @@ -5,7 +5,7 @@ const fs = require('fs'); // TODO: split up challenges // TODO: add appDesignSection? // ////SETUP HERE////// -const solutionName = 'findArrayIntersect'; +const solutionName = 'dataWork'; // TODO: look into setting up map or enum for this /* challenge || dataStructure || algorithm || designPattern || concept */ const codeChallengeType = 'challenge';