Final Exam Practice/questions.docx ---------------------------- JavaScript Final ---------------------------- Instructions: Using the files contained in this zip file, implement solutions for the...

I need assistance with the last 2 questions in the docx file


Final Exam Practice/questions.docx ---------------------------- JavaScript Final ---------------------------- Instructions: Using the files contained in this zip file, implement solutions for the questions below. Each question has a folder associated with it containing the file where you will write your code, and a second file that contains the Jasmine tests relevant to that question. Question folders are as follows: 1. sorting 2. stack 3. linked-list All tests can be run by opening test.html in your browser. If you want to comment out some tests to make it easier to focus on the question that you are working on, you are more than welcome to do so. Other than commenting, do not modify the tests in any way. 4. Using any algorithm of your choice, write a function called 'sort' that takes an array of numbers and returns a array of numbers sorted in ascending order Example: function sort([3, 5, 1, 7, 5]) ==> [1, 3, 5, 5, 7] ---------------------------------------------------------------------------------------------------------------------------- The following two questions focus on debugging. When you get into the industry, you do not always get to work on your own code; in fact you will probably spend equal time writing new code as you will fixing/maintaining code written by someone else, possibly with a differing code style. Isolate test suites by commenting out sections of the tests that you aren't focusing on while you fix other pieces, one test at a time. Use the debugging tools of the browser (set breakpoints, use the console to check values of variables, and look for errors) to help you find where the bugs in the code are. ---------------------------------------------------------------------------------------------------------------------------- 5. A broken implementation of a Stack has been provided along with tests. Fix all of the broken tests without breaking any of the others. 6. A broken implementation of a Linked List has been provided along with tests. Fix all of the broken tests without breaking any of the others. Final Exam Practice/README.md # javascript-final Final code test for the Javascript Module Final Exam Practice/sorting/sort.js function sort(list) { } Final Exam Practice/linked-list/linked-list.test.js describe('LinkedList', () => { let linkedList; beforeEach(() => { linkedList = new LinkedList(); }); describe('constructor', () => { it('should initialize the size of the linked list to 0', () => { expect(linkedList.listSize).toEqual(0); }); }); describe('insert', () => { it('should increase the size of the linked list', () => { linkedList.insert(5); expect(linkedList.listSize).toEqual(1); }); it('should set the first element of the linked list to the given value if the list is empty', () => { linkedList.insert(5); var firstElementValue = linkedList.firstNode.value; expect(firstElementValue).toEqual(5); }); it('should insert a second element after the first in sequence', () => { linkedList.insert(5); linkedList.insert(13); var firstElementValue = linkedList.firstNode.value; var secondElementValue = linkedList.firstNode.next.value; expect(firstElementValue).toEqual(5); expect(secondElementValue).toEqual(13); }); it('should insert a third element after the second in sequence', () => { linkedList.insert(5); linkedList.insert(13); linkedList.insert(17); var firstElement = linkedList.firstNode; var secondElement = firstElement.next; var thirdElement = secondElement.next; expect(firstElement.value).toEqual(5); expect(secondElement.value).toEqual(13); expect(thirdElement.value).toEqual(17); }); }); describe('remove', () => { var testNode1; var testNode2; var testNode3; var testNode4; var testNode5; beforeEach(() => { testNode1 = new Node(5); testNode2 = new Node(1); testNode3 = new Node(5); testNode4 = new Node(7); testNode5 = new Node(14); testNode1.next = testNode2; testNode2.next = testNode3; testNode3.next = testNode4; testNode4.next = testNode5; linkedList.firstNode = testNode1; linkedList.listSize = 5; }); it('should replace the start node with the second node when the first node value is 5 and the remove function is called with the value 5', () => { linkedList.remove(5); var firstNode = linkedList.firstNode; expect(firstNode).toEqual(testNode2); }); it('should decrease the size of the list by one when a node is removed', () => { expect(linkedList.listSize).toEqual(5); linkedList.remove(5); expect(linkedList.listSize).toEqual(4); }); it('should not remove anything if the value passed to the remove function does not exist in the list', () => { expect(linkedList.listSize).toEqual(5); linkedList.remove(74); expect(linkedList.listSize).toEqual(5); var node1 = linkedList.firstNode; var node2 = node1.next; var node3 = node2.next; var node4 = node3.next; var node5 = node4.next; expect(node1).toEqual(testNode1); expect(node2).toEqual(testNode2); expect(node3).toEqual(testNode3); expect(node4).toEqual(testNode4); expect(node5).toEqual(testNode5); }); it('should remove a node from the middle if that is where the value is found, and preserve the rest of the sequence', () => { linkedList.remove(7); var node1 = linkedList.firstNode; var node2 = node1.next; var node3 = node2.next; var node4 = node3.next; expect(node1).toEqual(testNode1); expect(node2).toEqual(testNode2); expect(node3).toEqual(testNode3); expect(node4).toEqual(testNode5); }); it('should not modify the list squence if the last node is the node to be removed', () => { linkedList.remove(14); var node1 = linkedList.firstNode; var node2 = node1.next; var node3 = node2.next; var node4 = node3.next; expect(node1).toEqual(testNode1); expect(node2).toEqual(testNode2); expect(node3).toEqual(testNode3); expect(node4).toEqual(testNode4); }); }); describe('contains', () => { beforeEach(() => { testNode1 = new Node(5); testNode2 = new Node(1); testNode3 = new Node(5); testNode4 = new Node(7); testNode5 = new Node(14); testNode1.next = testNode2; testNode2.next = testNode3; testNode3.next = testNode4; testNode4.next = testNode5; linkedList.firstNode = testNode1; linkedList.listSize = 5; }); it('should return true if the value is found in the sequence', () => { var result = linkedList.contains(1); expect(result).toEqual(true); }); it('should return false if the value is NOT found in the sequence', () => { var result = linkedList.contains(46); expect(result).toEqual(false); }); }); describe('size', () => { it('should return 5 when there are 5 elements in the linked list', () => { linkedList.insert(5); linkedList.insert(1); linkedList.insert(5); linkedList.insert(7); linkedList.insert(14); expect(linkedList.listSize).toEqual(5); }); }); }); Final Exam Practice/sorting/sort.test.js describe('sort', () => { it('should sort [2,4,1,3] to [1,2,3,4]', () => { let list = [2,4,1,3]; let expected = [1,2,3,4]; let result = sort(list); expect(result).toEqual(expected); }); it('should sort [3,5,6,7,1,2,9] to [1,2,3,5,7,9]', () => { let list = [3,5,6,7,1,2,9]; let expected = [1,2,3,5,6,7,9]; let result = sort(list); expect(result).toEqual(expected); }); it('should return an empty list when given an empty list', () => { let list = []; let expected = []; let result = sort(list); expect(result).toEqual(expected); }); it('should sort [1,3,4,3,1] to [1,1,3,3,4]', () => { let list = [1,3,4,3,1];
Apr 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here