Merge pull request #13343 from erictleung/fix/format-learning-about-stacks

Format Learn how a stack works challenge
pull/13577/head
Samuel Plumppu 2017-02-25 00:27:18 +01:00 committed by GitHub
commit 9c1441f59d
1 changed files with 13 additions and 12 deletions

View File

@ -46,23 +46,24 @@
"id": "587d8250367417b2b2512c5e",
"title": "Learn how a Stack Works",
"description": [
"You are probably familiar with stack of books on your table. You might have used the undo feature in your computer. You are also used to hitting the back button on your phone to go back to the previous view in your app.",
"You are probably familiar with stack of books on your table. You have likely used the undo feature of a text editor. You are also probably used to hitting the back button on your phone to go back to the previous view in your app.",
"You know what they all have in common? They all store the data in a way so that you can traverse backwards.",
"The topmost book in the stack was the one that was put there at the last. If you remove that book from your stack's top, you would expose the book that was put there before the last book and so on.",
"If you think about it, in all the above examples, you are getting Last-In-First-Out type of service. We will try to mimic this with our code - create a similar data storage scheme with JS arrays and functions that we always get back first what we put there last.",
"Oh, and did I mention such data storage scheme is called Stack! In particular, we would have to implement the push function that pushes JS object at the top of the stack; and pop function, that removes the JS object that's at the top of the stack at the current moment.",
"Instructions",
"Here we have a stack of homework assignments represented as an array: BIO12 is at the base, and PSY44 is at the top of the stack.",
"Remove the element on top of the stack, and Add CS50."
"The topmost book in the stack was the one that was put there last. If you remove that book from your stack's top, you would expose the book that was put there before the last book and so on.",
"If you think about it, in all the above examples, you are getting <dfn>Last-In-First-Out</dfn> type of service. We will try to mimic this with our code.",
"This data storage scheme is called a <dfn>Stack</dfn>. In particular, we would have to implement the <code>push()</code> method that pushes JavaScript objects at the top of the stack; and <code>pop()</code> method, that removes the JavaScript object that's at the top of the stack at the current moment.",
"<hr>",
"Here we have a stack of homework assignments represented as an array: <code>\"BIO12\"</code> is at the base, and <code>\"PSY44\"</code> is at the top of the stack.",
"Modify the given array and treat it like a <code>stack</code> using the JavaScript methods mentioned above. Remove the top element <code>\"BIO12\"</code> from the stack. Then add <code>\"CS50\"</code> to be the new top element of the stack."
],
"challengeSeed": [
"var homeworkStack = ['BIO12','HIS80','MAT122','PSY44'];",
"// Only change code below this line"
"var homeworkStack = [\"BIO12\",\"HIS80\",\"MAT122\",\"PSY44\"];",
"// Only change code below this line",
""
],
"tests": [
"assert(homeworkStack.length === 4, 'message: <code>homeworkStack</code> should only contain 4 elements');",
"assert(homeworkStack[3] === 'CS50', 'message: The last element in <code>homeworkStack</code> should be CS50');",
"assert(homeworkStack.indexOf('PSY44') === -1, 'message: <code>homeworkStack</code> should not contain PSY44');"
"assert(homeworkStack.length === 4, 'message: <code>homeworkStack</code> should only contain 4 elements.');",
"assert(homeworkStack[3] === 'CS50', 'message: The last element in <code>homeworkStack</code> should be <code>\"CS50\"</code>.');",
"assert(homeworkStack.indexOf('PSY44') === -1, 'message: <code>homeworkStack</code> should not contain <code>\"PSY44\"</code>.');"
],
"solutions": [],
"hints": [],