{"componentChunkName":"component---src-templates-assignment-template-js","path":"/assignments/assignment01","webpackCompilationHash":"041090671d318979d692","result":{"data":{"markdownRemark":{"htmlAst":{"type":"root","children":[{"type":"element","tagName":"h4","properties":{"id":"goals"},"children":[{"type":"element","tagName":"a","properties":{"href":"#goals","ariaLabel":"goals permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Goals"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Develop a basic familiarity with "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git"}]},{"type":"text","value":" and GitHub classroom"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Get started with basic JavaScript and Node.js"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Practice some of the functional aspects of JavaScript (higher-order\nfunctions and closures)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Practice test-driven development (TDD)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Use a linter to write more consistent, more maintainable, higher quality, code"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h2","properties":{"id":"prerequisites"},"children":[{"type":"element","tagName":"a","properties":{"href":"#prerequisites","ariaLabel":"prerequisites permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Prerequisites"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Install "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git"}]},{"type":"text","value":" and Node.js as described on the "},{"type":"element","tagName":"a","properties":{"href":"/~candrews/classes/cs312-f19/resources/getting_started.html"},"children":[{"type":"text","value":"Getting Started"}]},{"type":"text","value":" page"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Click the GitHub classroom "},{"type":"element","tagName":"a","properties":{"href":"https://classroom.github.com/a/cl3MzPeg"},"children":[{"type":"text","value":"link"}]},{"type":"text","value":" and then clone repository GitHub classroom creates to your local computer (see below)."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Update the "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"package.json"}]},{"type":"text","value":" file with your name and e-mail"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Install the package dependencies with "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"npm install"}]}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Click the GitHub classroom "},{"type":"element","tagName":"a","properties":{"href":"https://classroom.github.com/a/cl3MzPeg"},"children":[{"type":"text","value":"link"}]},{"type":"text","value":" to create a repository for yourself with the name \"pa1-<Your GitHub username>.git\", e.g. \"pa1-ChristopherPAndrews.git\". Clone that repository to your local computer:"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"text"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-text"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"git clone https://github.com/csci312-f19/pa1-<Your GitHub username>.git pa1"}]}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The clone command above will create a copy of the assignment skeleton in the local directory "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"pa1"}]},{"type":"text","value":"."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The above assumes the HHTPS interface to GitHub. GitHub offers both SSH and HTTPS-based interfaces to your repository. Using the former requires that you set up a "},{"type":"element","tagName":"a","properties":{"href":"https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/"},"children":[{"type":"text","value":"public-key with GitHub"}]},{"type":"text","value":". GitHub recommends the HTTPS for simplicity, but you may prefer to use SSH for added security. It is also possible to switch between the two using these "},{"type":"element","tagName":"a","properties":{"href":"https://help.github.com/articles/changing-a-remote-s-url/#switching-remote-urls-from-ssh-to-https"},"children":[{"type":"text","value":"instructions"}]},{"type":"text","value":"."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"NOTE:"}]},{"type":"text","value":" Because of some issues I am having with GitHub at the moment related to educational accounts, the repositories created by Classroom are "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"public"}]},{"type":"text","value":". As such, you should "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" push your work back to GitHub as everyone else in the class will be able to see it. I encourage you to occasionally commit your work to your local repository, just don't push it back to origin. I am hoping to have this straightened out shortly. "}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The assignment skeleton is a NPM package. Once you have cloned the repository edit the "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"package.json"}]},{"type":"text","value":" file to add your name. Then install the package dependencies with "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"npm install"}]},{"type":"text","value":"."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h2","properties":{"id":"background"},"children":[{"type":"element","tagName":"a","properties":{"href":"#background","ariaLabel":"background permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Background"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"running-and-testing-your-program"},"children":[{"type":"element","tagName":"a","properties":{"href":"#running-and-testing-your-program","ariaLabel":"running and testing your program permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Running and Testing Your Program"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can run your code interactively in Node.js by running "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":".load *filename*"}]},{"type":"text","value":" at the interpreter prompt (i.e., you have already typed "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"node"}]},{"type":"text","value":" on the command line). Do this to load your functions for testing. You can also run your file non-interactively, e.g. "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"node *filename*"}]},{"type":"text","value":"."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can and are encouraged to practice test-driven development, TDD, (as seen in class). The assignment skeleton is set up for unit testing with "},{"type":"element","tagName":"a","properties":{"href":"https://jestjs.io/en/"},"children":[{"type":"text","value":"Jest"}]},{"type":"text","value":". You can run the test suite with "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"npm test"}]},{"type":"text","value":". We converted the assignment examples into an initial set of tests in "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"index.test.js"}]},{"type":"text","value":". Note that these tests are currently failing and so are set to be "},{"type":"element","tagName":"a","properties":{"href":"https://jestjs.io/docs/en/api#describeskipname-fn"},"children":[{"type":"text","value":"skipped"}]},{"type":"text","value":". As you start developing \"unskip\" each test by changing "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"describe.skip"}]},{"type":"text","value":" to "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"describe"}]},{"type":"text","value":". Code that passes all of the provided tests is not guaranteed to be correct (thus we encourage you to add additional tests). However, code that fails one or more these tests does not meet the specification."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h2","properties":{"id":"assignment"},"children":[{"type":"element","tagName":"a","properties":{"href":"#assignment","ariaLabel":"assignment permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Assignment"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"part-1-truthiness"},"children":[{"type":"element","tagName":"a","properties":{"href":"#part-1-truthiness","ariaLabel":"part 1 truthiness permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Part 1: Truthiness"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"One of the places where people get tripped up in JavaScript is with \"falsy\" and \"truthy\" values. Do some online research to learn more. Write a function "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"howFalse(arr)"}]},{"type":"text","value":", which takes an array as an argument and returns an object containing a count of each kind of falsy value found in the array. The object should only have properties for falsy values that were actually present.  For example, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"howFalse([5, 0, 42, 'dalek', 3-3, 7, Math.sqrt(-1)])"}]},{"type":"text","value":" should return "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"{0: 2, NaN: 1}"}]},{"type":"text","value":". Your solution should not use a loop (at least, not an "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"explicit"}]},{"type":"text","value":" loop)."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"part-2-reduce"},"children":[{"type":"element","tagName":"a","properties":{"href":"#part-2-reduce","ariaLabel":"part 2 reduce permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Part 2: Reduce"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Write a function "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"myMax(arr)"}]},{"type":"text","value":" to find the largest value in an array using "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"reduce"}]},{"type":"text","value":". It should accept an array as an argument and return the largest value in the array (you can assume that the array is non-empty and that the values in the array are comparable). For example, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"myMax([1, 2, 3])"}]},{"type":"text","value":" should return "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"3"}]},{"type":"text","value":".  Your code should be of the form "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"const myMax = arr => arr.reduce(TODO);"}]},{"type":"text","value":", where "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"TODO"}]},{"type":"text","value":" should be replaced with the actual functionality. "}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"part-3-filtering"},"children":[{"type":"element","tagName":"a","properties":{"href":"#part-3-filtering","ariaLabel":"part 3 filtering permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Part 3: Filtering"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Write a function "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"threshold(objs, field, cutoff)"}]},{"type":"text","value":". This function takes in an array of objects ("},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"objs"}]},{"type":"text","value":"), the name of a property found in the objects ("},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"field"}]},{"type":"text","value":"), and a cutoff value ("},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"cutoff"}]},{"type":"text","value":"). The function should return an array of those objects in "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"objs"}]},{"type":"text","value":" whose values for "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"field"}]},{"type":"text","value":" are less than or equal to "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"cutoff"}]},{"type":"text","value":".  For example, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"threshold([{x: 4, y: 5}, {x: 2, y: 9}, {x: 1, y: 1}], 'y', 5)"}]},{"type":"text","value":" should return "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"[{x: 4, y: 5}, {x: 1, y: 1}]"}]},{"type":"text","value":". Your solution must use the array's "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"filter"}]},{"type":"text","value":" method. "}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"part-4-optional-arguments"},"children":[{"type":"element","tagName":"a","properties":{"href":"#part-4-optional-arguments","ariaLabel":"part 4 optional arguments permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Part 4: Optional arguments"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In JavaScript, functions can take an optional number of arguments. For example "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min"},"children":[{"type":"text","value":"Math.min"}]},{"type":"text","value":" can take an arbitrary number of values for comparison. Write a function "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"myMin()"}]},{"type":"text","value":" that duplicates this functionality (without just calling "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"Math.min"}]},{"type":"text","value":"). As an example, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"myMin(1, 2, 3)"}]},{"type":"text","value":" should return "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":". Your function should match the behavior of "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"Math.min"}]},{"type":"text","value":" exactly, including the corner cases like no arguments."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"part-5-longest-common-subsequence"},"children":[{"type":"element","tagName":"a","properties":{"href":"#part-5-longest-common-subsequence","ariaLabel":"part 5 longest common subsequence permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Part 5: Longest common subsequence"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Find the longest common subsequence between two strings."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Write a function "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"longestCommonSubsequence(str1, str2)"}]},{"type":"text","value":". It should (obviously) return the longest common subsequence. The subsequence does not need to be continuous, just in the same order. For example, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"longestCommonSubsequence('afbwc', 'yabzcx')"}]},{"type":"text","value":" should return "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"'abc'"}]},{"type":"text","value":". There are multiple solutions to this problem, but your solution should use a recursive \"top-down\" approach.\n\nConsider a function "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"f(i,j)"}]},{"type":"text","value":" that takes as arguments the indices of the last character in each string. As a base case, if either one of those indices is less than zero, then we know there is no common subsequence. We then have two recursive cases. If the characters are the same, we know that the character appears at the end of the common subsequence, so we can tack it on the end of the longest subsequence of the rest of the two strings (which we find recursively with f(i-1, j-1)). If the last character doesn't agree, then the longest subsequence is the longer of f(i, j-1) or f(i-1, j) (i.e., we can throw away the last character from one of the two lists, but we don't know which). To break ties, if f(i, j-1) and f(i-1, j) are the same length, pick f(i, j-1). "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"Note: while we could have passed the actual strings around and chopped them up as we went with the built-in "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"substring"}]},{"type":"text","value":" method, working with indices will be easier and more efficient."}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You could write this recursive function fairly easily, but it will have exponential time complexity. So, we would like you to use a closure and "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"memoization"}]},{"type":"text","value":" (not a typo), to store values you have seen before to short-circuit long recursive chains. Memoize by building a cache of the values you have already calculated so you don't have to calculate them again. In languages that support closures like JavaScript, the \"memo\" is easily hidden by creating a closure containing it. So, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"longestCommonSubsequence(str1, str2)"}]},{"type":"text","value":" should encapsulate at least two objects: the recursive function described above, and the a 2-D array that allows you to look up the longest subsequence given an "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"i,j"}]},{"type":"text","value":" pair. "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"Note: The longest common subsequence of two strings may not be unique. In cases where they are not, the output from the algorithm described above will be the one considered correct."}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"part-6-finishing-up"},"children":[{"type":"element","tagName":"a","properties":{"href":"#part-6-finishing-up","ariaLabel":"part 6 finishing up permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Part 6: Finishing Up"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Once your program is working make sure you don't have any style issues by running ESLint via "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"npm run lint"}]},{"type":"text","value":". ESLint can fix many of the errors automatically by running "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"npm run lint -- --fix"}]},{"type":"text","value":" (although since ESLint can sometimes introduce errors during this process, we suggest committing your code before running \"fix\" so you can rollback any changes). To get full credit for the style portion of the assignment your code must have zero ESLint errors."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Notice that there is an additional file in your directory, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":".gitignore"}]},{"type":"text","value":", which specifies files that should not be tracked by Git. It is good practice to create this file first in your repository to prevent undesired files from getting committed. Here we have provided a relevant "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":".gitignore"}]},{"type":"text","value":" file in the skeleton. In general we want to exclude platform specific files, like the OSX .DS_Store files, any files that are automatically generated as well as files containing secrets such as API keys."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If you haven't done so already commit your changes to index.js:"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Start by running "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git status"}]},{"type":"text","value":" in the terminal in the assignment directory to see how your modified files are reported."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Then add the modified files to stage them for the commit, i.e. "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git add index.js"}]},{"type":"text","value":". The staging area now contains the files whose changes will be committed."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Run "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git status"}]},{"type":"text","value":" again to see the how staged files are reported."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Commit your changes with "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git commit -m \"Your pithy commit message\""}]},{"type":"text","value":" (replace \"Your pithy commit message\" with a pithy but informative commit message, quotes are required). You can also skip the "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"-m"}]},{"type":"text","value":" option. If you do so, "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git"}]},{"type":"text","value":" will open a text editor for you to write your commit message."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Run "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"git log"}]},{"type":"text","value":" to see your commit reported."}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Normally, you would follow the same process that you followed for the practical to push your changes to GitHub and the submit to Gradescope. However, since the repositories you created are "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"public"}]},{"type":"text","value":", please do not push to them until "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"after"}]},{"type":"text","value":" the assignment deadline. "}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Run "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"npm run submission"}]},{"type":"text","value":", which will create a file called "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"submission.zip"}]},{"type":"text","value":" in your directory. Go to "},{"type":"element","tagName":"a","properties":{"href":"https://www.gradescope.com/courses/60802"},"children":[{"type":"text","value":"Gradescope"}]},{"type":"text","value":", select the assignment, and then use the \"Upload\" submission method to upload the zip file."}]},{"type":"text","value":"\n"},{"type":"comment","value":" \nFinally submit your assignment by pushing your changes to the GitHub classroom via `git push --all origin` and then submitting your repository to Gradescope as described [here](/resources/gradescope.html). You can submit (push to GitHub and submit to Gradescope) multiple times. The last submission before the deadline will be the one graded. "},{"type":"text","value":"\n"},{"type":"element","tagName":"h2","properties":{"id":"grading"},"children":[{"type":"element","tagName":"a","properties":{"href":"#grading","ariaLabel":"grading permalink","className":["anchor"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Grading"}]},{"type":"text","value":"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"},{"type":"element","tagName":"table","properties":{},"children":[{"type":"element","tagName":"thead","properties":{},"children":[{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Points"}]},{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Section"}]}]}]},{"type":"element","tagName":"tbody","properties":{},"children":[{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Truthiness"}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Reduce"}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Filtering"}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Optional arguments"}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Longest common subsequence"}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Style"}]}]}]}]}],"data":{"quirksMode":false}},"frontmatter":{"dueDate":"2019-09-20 5p","path":"/assignments/assignment01","title":"CS 312 - Assignment One","name":"Assignment 1"},"parent":{"__typename":"File","id":"cd53a296-5ce5-544e-9a68-017f2b7a1a6a","name":"assignment01","modifiedTime":"Oct 7 2019 13:30"}}},"pageContext":{"isCreatedByStatefulCreatePages":false}}}