Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1,2,3,4 without the extension JavaScript Assignment: State Borders Eckel, TIISST Web Design. Spring 2019 that refer to a backing data structure of your choice based

1,2,3,4 without the extension image text in transcribed
JavaScript Assignment: State Borders Eckel, TIISST Web Design. Spring 2019 that refer to a backing data structure of your choice based on the US map 4 points, and each function is worth 4 points, for a total of 20. These are the four functions Your task is to make four lavaScript functions The data structure is worth points 1. dostatesBorder (atatel, the given states share a border, false f .scate2) should return true i F7 2. getstateBorders istate1) should return an array of the states that border statel. 3. getcloseStates (state1) should return the list of all states reachable from the original state by crossing no more than two state borders. In other words, it should return any states that border the input state, as well as any states that border any of those. For instance, Washington borders Oregon and idaho, so it would return an array of all of the states that border Oregon or Idaho, as well as Oregon and Idaho themselves. This must 9 include a correct, authentic use of the for Each function (half credit if not). ateswithBorders (num) should return an array of all of the states that border exactly num other states This must include a correct, authentic use of the reduce function (half credit if not) The design of the backing data structure is up to you. You may enumerate states or use their names or postal coder: you may use arrays, objects, an adjacency matrix, etc. Whatever makes sense, as long as you code the structure. I strongly recommend starting with a small adjacency matrix/ object that contains only four or five states and making sure your code works on that before creating the complete data structure. Some details: . This is not an interactive e program; you are not taking any input from the console, as you might have in Java or Python. I will specify the particular test calls that will be used later, and you will just add them to the JS file. When any function is called, it should accept a variety of input strings successfully. Specifically, inputs can be: o postal abbreviations in upper case only (like "NJ" but not "ni) or When the second function returns the array of states that border statel, the format should be full state "Washington" refers to the state. "Washington DC" (not case sensitive) or "District of Columbia" (not case o full state names in any case (so "New Jersey" and "new jersey-and-NEw JERSEY-would all work) names capitalized,so ["Oregon", "Idaho"] would be the correct output for Washington. sensitive) or "DC" (case sensitive) refer to the district. I will not grade you on any ambiguous border situations (like the fact that Michigan and illinois technically share a water border, or whether the four corners states count as bordering the states they only touch on the corner) Extension A: Make a text file where each line is a pair of states that share a border. Then, learn how to do JavaScript file Vo well enough to read in the file and construct your data structure on the fly instead of hardcoding it. Extension 8: Implement all of the above again using a completely different backing data structure (ie, if you used an object, use an array instead, etc.) Use this as an opportunity to gain familiarity with the particulars of different areas of JavaScript. If this seems unexciting, you aren't thinking creatively enough - figure out how to make a graph, or store the entire thing as a single giant but organized and searchable string, or something else unusual or difficult Extension C: Implement a function that finds the border crossings. (If you've previously taken or are currently taking Al, this should be a familiar challenge.) shortest path between any two states, as measured by number of JavaScript Assignment: State Borders Eckel, TIISST Web Design. Spring 2019 that refer to a backing data structure of your choice based on the US map 4 points, and each function is worth 4 points, for a total of 20. These are the four functions Your task is to make four lavaScript functions The data structure is worth points 1. dostatesBorder (atatel, the given states share a border, false f .scate2) should return true i F7 2. getstateBorders istate1) should return an array of the states that border statel. 3. getcloseStates (state1) should return the list of all states reachable from the original state by crossing no more than two state borders. In other words, it should return any states that border the input state, as well as any states that border any of those. For instance, Washington borders Oregon and idaho, so it would return an array of all of the states that border Oregon or Idaho, as well as Oregon and Idaho themselves. This must 9 include a correct, authentic use of the for Each function (half credit if not). ateswithBorders (num) should return an array of all of the states that border exactly num other states This must include a correct, authentic use of the reduce function (half credit if not) The design of the backing data structure is up to you. You may enumerate states or use their names or postal coder: you may use arrays, objects, an adjacency matrix, etc. Whatever makes sense, as long as you code the structure. I strongly recommend starting with a small adjacency matrix/ object that contains only four or five states and making sure your code works on that before creating the complete data structure. Some details: . This is not an interactive e program; you are not taking any input from the console, as you might have in Java or Python. I will specify the particular test calls that will be used later, and you will just add them to the JS file. When any function is called, it should accept a variety of input strings successfully. Specifically, inputs can be: o postal abbreviations in upper case only (like "NJ" but not "ni) or When the second function returns the array of states that border statel, the format should be full state "Washington" refers to the state. "Washington DC" (not case sensitive) or "District of Columbia" (not case o full state names in any case (so "New Jersey" and "new jersey-and-NEw JERSEY-would all work) names capitalized,so ["Oregon", "Idaho"] would be the correct output for Washington. sensitive) or "DC" (case sensitive) refer to the district. I will not grade you on any ambiguous border situations (like the fact that Michigan and illinois technically share a water border, or whether the four corners states count as bordering the states they only touch on the corner) Extension A: Make a text file where each line is a pair of states that share a border. Then, learn how to do JavaScript file Vo well enough to read in the file and construct your data structure on the fly instead of hardcoding it. Extension 8: Implement all of the above again using a completely different backing data structure (ie, if you used an object, use an array instead, etc.) Use this as an opportunity to gain familiarity with the particulars of different areas of JavaScript. If this seems unexciting, you aren't thinking creatively enough - figure out how to make a graph, or store the entire thing as a single giant but organized and searchable string, or something else unusual or difficult Extension C: Implement a function that finds the border crossings. (If you've previously taken or are currently taking Al, this should be a familiar challenge.) shortest path between any two states, as measured by number of

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions