fix(curriculum): Consolidated comments for JavaScript Algorithms and Data Structures challenges - part 1 of 4 (#38258)
* fix: consolidate/remove comments * fix: remove => from comment * fix: reverted changes to add same changes to another PR * fix: removed 'the' from sentence Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: removed 'the' from the sentence Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
		| @@ -41,17 +41,14 @@ tests: | ||||
| <div id='js-seed'> | ||||
|  | ||||
| ```js | ||||
| /** | ||||
|  * A long process to prepare tea. | ||||
|  * @return {string} A cup of tea. | ||||
|  **/ | ||||
| // Function that returns a string representing a cup of green tea | ||||
| const prepareTea = () => 'greenTea'; | ||||
|  | ||||
| /** | ||||
|  * Get given number of cups of tea. | ||||
|  * @param {number} numOfCups Number of required cups of tea. | ||||
|  * @return {Array<string>} Given amount of tea cups. | ||||
|  **/ | ||||
| /* | ||||
| Given a function (representing the tea type) and number of cups needed, the | ||||
| following function returns an array of strings (each representing a cup of | ||||
| a specific type of tea). | ||||
| */ | ||||
| const getTea = (numOfCups) => { | ||||
|   const teaCups = []; | ||||
|  | ||||
| @@ -59,15 +56,12 @@ const getTea = (numOfCups) => { | ||||
|     const teaCup = prepareTea(); | ||||
|     teaCups.push(teaCup); | ||||
|   } | ||||
|  | ||||
|   return teaCups; | ||||
| }; | ||||
|  | ||||
| // Add your code below this line | ||||
|  | ||||
| const tea4TeamFCC = null; // :( | ||||
|  | ||||
| // Add your code above this line | ||||
| // Only change code below this line | ||||
| const tea4TeamFCC = null; | ||||
| // Only change code above this line | ||||
|  | ||||
| console.log(tea4TeamFCC); | ||||
| ``` | ||||
|   | ||||
| @@ -15,7 +15,10 @@ Adding one to a number is not very exciting, but we can apply these principles w | ||||
|  | ||||
| ## Instructions | ||||
| <section id='instructions'> | ||||
| Rewrite the code so the global array <code>bookList</code> is not changed inside either function. The <code>add</code> function should add the given <code>bookName</code> to the end of an array. The <code>remove</code> function should remove the given <code>bookName</code> from an array. Both functions should return an array, and any new parameters should be added before the <code>bookName</code> parameter. | ||||
| Rewrite the code so the global array <code>bookList</code> is not changed inside either function. The <code>add</code> function should add the given <code>bookName</code> to the end of the array passed to it and return a new array (list). The <code>remove</code> function should remove the given <code>bookName</code> from the array passed to it. | ||||
|  | ||||
| <strong>Note:</strong> Both functions should return an array, and any new parameters should be added before the <code>bookName</code> parameter. | ||||
|  | ||||
| </section> | ||||
|  | ||||
| ## Tests | ||||
| @@ -45,22 +48,16 @@ tests: | ||||
| // the global variable | ||||
| var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; | ||||
|  | ||||
| /* This function should add a book to the list and return the list */ | ||||
| // New parameters should come before bookName | ||||
|  | ||||
| // Add your code below this line | ||||
| // Change code below this line | ||||
| function add (bookName) { | ||||
|  | ||||
|   bookList.push(bookName); | ||||
|   return bookList; | ||||
|    | ||||
|   // Add your code above this line | ||||
|   // Change code above this line | ||||
| } | ||||
|  | ||||
| /* This function should remove a book from the list and return the list */ | ||||
| // New parameters should come before the bookName one | ||||
|  | ||||
| // Add your code below this line | ||||
| // Change code below this line | ||||
| function remove (bookName) { | ||||
|   var book_index = bookList.indexOf(bookName); | ||||
|   if (book_index >= 0) { | ||||
| @@ -68,7 +65,7 @@ function remove (bookName) { | ||||
|     bookList.splice(book_index, 1); | ||||
|     return bookList; | ||||
|  | ||||
|     // Add your code above this line | ||||
|     // Change code above this line | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -89,22 +86,13 @@ console.log(bookList); | ||||
| <section id='solution'> | ||||
|  | ||||
| ```js | ||||
| // the global variable | ||||
| // The global variable | ||||
| var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; | ||||
|  | ||||
| /* This function should add a book to the list and return the list */ | ||||
| // New parameters should come before the bookName one | ||||
|  | ||||
| // Add your code below this line | ||||
| function add (bookList, bookName) { | ||||
|   return [...bookList, bookName]; | ||||
|   // Add your code above this line | ||||
| } | ||||
|  | ||||
| /* This function should remove a book from the list and return the list */ | ||||
| // New parameters should come before the bookName one | ||||
|  | ||||
| // Add your code below this line | ||||
| function remove (bookList, bookName) { | ||||
|   const bookListCopy = [...bookList]; | ||||
|   const bookNameIndex = bookList.indexOf(bookName); | ||||
| @@ -112,7 +100,6 @@ function remove (bookList, bookName) { | ||||
|     bookListCopy.splice(bookNameIndex, 1); | ||||
|   } | ||||
|   return bookListCopy; | ||||
|   // Add your code above this line | ||||
| } | ||||
|  | ||||
| var newBookList = add(bookList, 'A Brief History of Time'); | ||||
|   | ||||
| @@ -46,24 +46,17 @@ tests: | ||||
| <div id='js-seed'> | ||||
|  | ||||
| ```js | ||||
| /** | ||||
|  * A long process to prepare green tea. | ||||
|  * @return {string} A cup of green tea. | ||||
|  **/ | ||||
| // Function that returns a string representing a cup of green tea | ||||
| const prepareGreenTea = () => 'greenTea'; | ||||
|  | ||||
| /** | ||||
|  * A long process to prepare black tea. | ||||
|  * @return {string} A cup of black tea. | ||||
|  **/ | ||||
| // Function that returns a string representing a cup of black tea | ||||
| const prepareBlackTea = () => 'blackTea'; | ||||
|  | ||||
| /** | ||||
|  * Get given number of cups of tea. | ||||
|  * @param {function():string} prepareTea The type of tea preparing function. | ||||
|  * @param {number} numOfCups Number of required cups of tea. | ||||
|  * @return {Array<string>} Given amount of tea cups. | ||||
|  **/ | ||||
| /* | ||||
| Given a function (representing the tea type) and number of cups needed, the | ||||
| following function returns an array of strings (each representing a cup of | ||||
| a specific type of tea). | ||||
| */ | ||||
| const getTea = (prepareTea, numOfCups) => { | ||||
|   const teaCups = []; | ||||
|  | ||||
| @@ -71,16 +64,13 @@ const getTea = (prepareTea, numOfCups) => { | ||||
|     const teaCup = prepareTea(); | ||||
|     teaCups.push(teaCup); | ||||
|   } | ||||
|  | ||||
|   return teaCups; | ||||
| }; | ||||
|  | ||||
| // Add your code below this line | ||||
|  | ||||
| const tea4GreenTeamFCC = null; // :( | ||||
| const tea4BlackTeamFCC = null; // :( | ||||
|  | ||||
| // Add your code above this line | ||||
| // Only change code below this line | ||||
| const tea4GreenTeamFCC = null; | ||||
| const tea4BlackTeamFCC = null; | ||||
| // Only change code above this line | ||||
|  | ||||
| console.log( | ||||
|   tea4GreenTeamFCC, | ||||
|   | ||||
| @@ -47,7 +47,7 @@ tests: | ||||
| ```js | ||||
| // tabs is an array of titles of each site open within the window | ||||
| var Window = function(tabs) { | ||||
|   this.tabs = tabs; // we keep a record of the array inside the object | ||||
|   this.tabs = tabs; // We keep a record of the array inside the object | ||||
| }; | ||||
|  | ||||
| // When you join two windows into one window | ||||
| @@ -58,7 +58,7 @@ Window.prototype.join = function (otherWindow) { | ||||
|  | ||||
| // When you open a new tab at the end | ||||
| Window.prototype.tabOpen = function (tab) { | ||||
|   this.tabs.push('new tab'); // let's open a new tab for now | ||||
|   this.tabs.push('new tab'); // Let's open a new tab for now | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| @@ -67,10 +67,10 @@ Window.prototype.tabClose = function (index) { | ||||
|  | ||||
|   // Only change code below this line | ||||
|  | ||||
|   var tabsBeforeIndex = this.tabs.splice(0, index); // get the tabs before the tab | ||||
|   var tabsAfterIndex = this.tabs.splice(index + 1); // get the tabs after the tab | ||||
|   var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab | ||||
|   var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab | ||||
|  | ||||
|   this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together | ||||
|   this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together | ||||
|  | ||||
|   // Only change code above this line | ||||
|  | ||||
| @@ -80,13 +80,13 @@ Window.prototype.tabClose = function (index) { | ||||
| // Let's create three browser windows | ||||
| var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites | ||||
| var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites | ||||
| var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); //  Entertainment sites | ||||
| var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites | ||||
|  | ||||
| // Now perform the tab opening, closing, and other operations | ||||
| var finalTabs = socialWindow | ||||
|                     .tabOpen() // Open a new tab for cat memes | ||||
|                     .join(videoWindow.tabClose(2)) // Close third tab in video window, and join | ||||
|                     .join(workWindow.tabClose(1).tabOpen()); | ||||
|   .tabOpen() // Open a new tab for cat memes | ||||
|   .join(videoWindow.tabClose(2)) // Close third tab in video window, and join | ||||
|   .join(workWindow.tabClose(1).tabOpen()); | ||||
| console.log(finalTabs.tabs); | ||||
| ``` | ||||
|  | ||||
| @@ -102,7 +102,7 @@ console.log(finalTabs.tabs); | ||||
| ```js | ||||
| // tabs is an array of titles of each site open within the window | ||||
| var Window = function(tabs) { | ||||
|   this.tabs = tabs; // we keep a record of the array inside the object | ||||
|   this.tabs = tabs; // We keep a record of the array inside the object | ||||
| }; | ||||
|  | ||||
| // When you join two windows into one window | ||||
| @@ -113,16 +113,16 @@ Window.prototype.join = function (otherWindow) { | ||||
|  | ||||
| // When you open a new tab at the end | ||||
| Window.prototype.tabOpen = function (tab) { | ||||
|   this.tabs.push('new tab'); // let's open a new tab for now | ||||
|   this.tabs.push('new tab'); // Let's open a new tab for now | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| // When you close a tab | ||||
| Window.prototype.tabClose = function (index) { | ||||
|   var tabsBeforeIndex = this.tabs.slice(0, index); // get the tabs before the tab | ||||
|   var tabsAfterIndex = this.tabs.slice(index + 1); // get the tabs after the tab | ||||
|   var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab | ||||
|   var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab | ||||
|  | ||||
|   this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together | ||||
|   this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together | ||||
|   return this; | ||||
|  }; | ||||
|  | ||||
| @@ -133,9 +133,9 @@ var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); //  Enter | ||||
|  | ||||
| // Now perform the tab opening, closing, and other operations | ||||
| var finalTabs = socialWindow | ||||
|                     .tabOpen() // Open a new tab for cat memes | ||||
|                     .join(videoWindow.tabClose(2)) // Close third tab in video window, and join | ||||
|                     .join(workWindow.tabClose(1).tabOpen()); | ||||
|   .tabOpen() // Open a new tab for cat memes | ||||
|   .join(videoWindow.tabClose(2)) // Close third tab in video window, and join | ||||
|   .join(workWindow.tabClose(1).tabOpen()); | ||||
| ``` | ||||
|  | ||||
| </section> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user