fix(challenge-md): Fix quotes that failed in the transform

This commit is contained in:
Bouncey
2018-10-08 01:01:53 +01:00
committed by mrugesh mohapatra
parent 392b28fa55
commit a859035023
1333 changed files with 5710 additions and 5710 deletions

View File

@ -22,33 +22,33 @@ Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-yo
```yml
tests:
- text: '<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.'
testString: 'assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5], ''<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.'');'
testString: 'assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5], "<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.");'
- text: '<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should contain only three elements.'
testString: 'assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3, ''<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should contain only three elements.'');'
testString: 'assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3, "<code>sym([1, 2, 3], [5, 2, 1, 4])</code> should contain only three elements.");'
- text: '<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.'
testString: 'assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5], ''<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.'');'
testString: 'assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5], "<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should return <code>[3, 4, 5]</code>.");'
- text: '<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should contain only three elements.'
testString: 'assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3, ''<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should contain only three elements.'');'
testString: 'assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3, "<code>sym([1, 2, 3, 3], [5, 2, 1, 4])</code> should contain only three elements.");'
- text: '<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should return <code>[3, 4, 5]</code>.'
testString: 'assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5], ''<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should return <code>[3, 4, 5]</code>.'');'
testString: 'assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5], "<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should return <code>[3, 4, 5]</code>.");'
- text: '<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should contain only three elements.'
testString: 'assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3, ''<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should contain only three elements.'');'
testString: 'assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3, "<code>sym([1, 2, 3], [5, 2, 1, 4, 5])</code> should contain only three elements.");'
- text: '<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should return <code>[1, 4, 5]</code>'
testString: 'assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5], ''<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should return <code>[1, 4, 5]</code>'');'
testString: 'assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5], "<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should return <code>[1, 4, 5]</code>");'
- text: '<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should contain only three elements.'
testString: 'assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3, ''<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should contain only three elements.'');'
testString: 'assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3, "<code>sym([1, 2, 5], [2, 3, 5], [3, 4, 5])</code> should contain only three elements.");'
- text: '<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should return <code>[1, 4, 5]</code>.'
testString: 'assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5], ''<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should return <code>[1, 4, 5]</code>.'');'
testString: 'assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5], "<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should return <code>[1, 4, 5]</code>.");'
- text: '<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should contain only three elements.'
testString: 'assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3, ''<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should contain only three elements.'');'
testString: 'assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3, "<code>sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])</code> should contain only three elements.");'
- text: '<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should return <code>[2, 3, 4, 6, 7]</code>.'
testString: 'assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]), [2, 3, 4, 6, 7], ''<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should return <code>[2, 3, 4, 6, 7]</code>.'');'
testString: 'assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]), [2, 3, 4, 6, 7], "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should return <code>[2, 3, 4, 6, 7]</code>.");'
- text: '<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should contain only five elements.'
testString: 'assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]).length, 5, ''<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should contain only five elements.'');'
testString: 'assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]).length, 5, "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])</code> should contain only five elements.");'
- text: '<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should return <code>[1, 2, 4, 5, 6, 7, 8, 9]</code>.'
testString: 'assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]), [1, 2, 4, 5, 6, 7, 8, 9], ''<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should return <code>[1, 2, 4, 5, 6, 7, 8, 9]</code>.'');'
testString: 'assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]), [1, 2, 4, 5, 6, 7, 8, 9], "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should return <code>[1, 2, 4, 5, 6, 7, 8, 9]</code>.");'
- text: '<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should contain only eight elements.'
testString: 'assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]).length, 8, ''<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should contain only eight elements.'');'
testString: 'assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]).length, 8, "<code>sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])</code> should contain only eight elements.");'
```
@ -82,7 +82,7 @@ function sym() {
var arrays = [].slice.call(arguments);
return arrays.reduce(function (symDiff, arr) {
return symDiff.concat(arr).filter(function (val, idx, theArr) {
return theArr.indexOf(val) === idx
return theArr.indexOf(val) === idx
&& (symDiff.indexOf(val) === -1 || arr.indexOf(val) === -1);
});
});

View File

@ -24,13 +24,13 @@ This method requires multiple iterations through the array and for average and w
```yml
tests:
- text: <code>bubbleSort</code> is a function.
testString: 'assert(typeof bubbleSort == ''function'', ''<code>bubbleSort</code> is a function.'');'
testString: 'assert(typeof bubbleSort == "function", "<code>bubbleSort</code> is a function.");'
- text: <code>bubbleSort</code> returns a sorted array (least to greatest).
testString: 'assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), ''<code>bubbleSort</code> returns a sorted array (least to greatest).'');'
testString: 'assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>bubbleSort</code> returns a sorted array (least to greatest).");'
- text: <code>bubbleSort</code> returns an array that is unchanged except for order.
testString: 'assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], ''<code>bubbleSort</code> returns an array that is unchanged except for order.'');'
testString: 'assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>bubbleSort</code> returns an array that is unchanged except for order.");'
- text: <code>bubbleSort</code> should not use the built-in <code>.sort()</code> method.
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, ''<code>bubbleSort</code> should not use the built-in <code>.sort()</code> method.'');'
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>bubbleSort</code> should not use the built-in <code>.sort()</code> method.");'
```

View File

@ -22,13 +22,13 @@ The next sorting method we'll look at is insertion sort. This method works by bu
```yml
tests:
- text: <code>insertionSort</code> is a function.
testString: 'assert(typeof insertionSort == ''function'', ''<code>insertionSort</code> is a function.'');'
testString: 'assert(typeof insertionSort == "function", "<code>insertionSort</code> is a function.");'
- text: <code>insertionSort</code> returns a sorted array (least to greatest).
testString: 'assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), ''<code>insertionSort</code> returns a sorted array (least to greatest).'');'
testString: 'assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>insertionSort</code> returns a sorted array (least to greatest).");'
- text: <code>insertionSort</code> returns an array that is unchanged except for order.
testString: 'assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], ''<code>insertionSort</code> returns an array that is unchanged except for order.'');'
testString: 'assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>insertionSort</code> returns an array that is unchanged except for order.");'
- text: <code>insertionSort</code> should not use the built-in <code>.sort()</code> method.
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, ''<code>insertionSort</code> should not use the built-in <code>.sort()</code> method.'');'
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>insertionSort</code> should not use the built-in <code>.sort()</code> method.");'
```

View File

@ -26,13 +26,13 @@ As an aside, this will be the last sorting algorithm we cover here. However, lat
```yml
tests:
- text: <code>mergeSort</code> is a function.
testString: 'assert(typeof mergeSort == ''function'', ''<code>mergeSort</code> is a function.'');'
testString: 'assert(typeof mergeSort == "function", "<code>mergeSort</code> is a function.");'
- text: <code>mergeSort</code> returns a sorted array (least to greatest).
testString: 'assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), ''<code>mergeSort</code> returns a sorted array (least to greatest).'');'
testString: 'assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>mergeSort</code> returns a sorted array (least to greatest).");'
- text: <code>mergeSort</code> returns an array that is unchanged except for order.
testString: 'assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], ''<code>mergeSort</code> returns an array that is unchanged except for order.'');'
testString: 'assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>mergeSort</code> returns an array that is unchanged except for order.");'
- text: <code>mergeSort</code> should not use the built-in <code>.sort()</code> method.
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, ''<code>mergeSort</code> should not use the built-in <code>.sort()</code> method.'');'
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>mergeSort</code> should not use the built-in <code>.sort()</code> method.");'
```

View File

@ -23,13 +23,13 @@ Quick sort is a very efficient sorting method, providing <i>O(nlog(n))</i> perfo
```yml
tests:
- text: <code>quickSort</code> is a function.
testString: 'assert(typeof quickSort == ''function'', ''<code>quickSort</code> is a function.'');'
testString: 'assert(typeof quickSort == "function", "<code>quickSort</code> is a function.");'
- text: <code>quickSort</code> returns a sorted array (least to greatest).
testString: 'assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), ''<code>quickSort</code> returns a sorted array (least to greatest).'');'
testString: 'assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>quickSort</code> returns a sorted array (least to greatest).");'
- text: <code>quickSort</code> returns an array that is unchanged except for order.
testString: 'assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], ''<code>quickSort</code> returns an array that is unchanged except for order.'');'
testString: 'assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>quickSort</code> returns an array that is unchanged except for order.");'
- text: <code>quickSort</code> should not use the built-in <code>.sort()</code> method.
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, ''<code>quickSort</code> should not use the built-in <code>.sort()</code> method.'');'
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>quickSort</code> should not use the built-in <code>.sort()</code> method.");'
```

View File

@ -22,13 +22,13 @@ Here we will implement selection sort. Selection sort works by selecting the min
```yml
tests:
- text: <code>selectionSort</code> is a function.
testString: 'assert(typeof selectionSort == ''function'', ''<code>selectionSort</code> is a function.'');'
testString: 'assert(typeof selectionSort == "function", "<code>selectionSort</code> is a function.");'
- text: <code>selectionSort</code> returns a sorted array (least to greatest).
testString: 'assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), ''<code>selectionSort</code> returns a sorted array (least to greatest).'');'
testString: 'assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), "<code>selectionSort</code> returns a sorted array (least to greatest).");'
- text: <code>selectionSort</code> returns an array that is unchanged except for order.
testString: 'assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], ''<code>selectionSort</code> returns an array that is unchanged except for order.'');'
testString: 'assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], "<code>selectionSort</code> returns an array that is unchanged except for order.");'
- text: <code>selectionSort</code> should not use the built-in <code>.sort()</code> method.
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, ''<code>selectionSort</code> should not use the built-in <code>.sort()</code> method.'');'
testString: 'assert.strictEqual(code.search(/\.sort\(/), -1, "<code>selectionSort</code> should not use the built-in <code>.sort()</code> method.");'
```

View File

@ -21,17 +21,17 @@ Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-yo
```yml
tests:
- text: The function <code>updateInventory</code> should return an array.
testString: 'assert.isArray(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), ''The function <code>updateInventory</code> should return an array.'');'
testString: 'assert.isArray(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), "The function <code>updateInventory</code> should return an array.");'
- text: '<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return an array with a length of 6.'
testString: 'assert.equal(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]).length, 6, ''<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return an array with a length of 6.'');'
testString: 'assert.equal(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]).length, 6, "<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return an array with a length of 6.");'
- text: '<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]</code>.'
testString: 'assert.deepEqual(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), [[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]], ''<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]</code>.'');'
testString: 'assert.deepEqual(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), [[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]], "<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]</code>.");'
- text: '<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])</code> should return <code>[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]</code>.'
testString: 'assert.deepEqual(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], []), [[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], ''<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])</code> should return <code>[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]</code>.'');'
testString: 'assert.deepEqual(updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], []), [[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], "<code>updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])</code> should return <code>[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]</code>.");'
- text: '<code>updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]</code>.'
testString: 'assert.deepEqual(updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), [[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]], ''<code>updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]</code>.'');'
testString: 'assert.deepEqual(updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]]), [[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]], "<code>updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])</code> should return <code>[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]</code>.");'
- text: '<code>updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])</code> should return <code>[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]</code>.'
testString: 'assert.deepEqual(updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]]), [[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]], ''<code>updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])</code> should return <code>[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]</code>.'');'
testString: 'assert.deepEqual(updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]]), [[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]], "<code>updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])</code> should return <code>[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]</code>.");'
```

View File

@ -22,25 +22,25 @@ Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-yo
```yml
tests:
- text: <code>permAlone("aab")</code> should return a number.
testString: 'assert.isNumber(permAlone(''aab''), ''<code>permAlone("aab")</code> should return a number.'');'
testString: 'assert.isNumber(permAlone("aab"), "<code>permAlone("aab")</code> should return a number.");'
- text: <code>permAlone("aab")</code> should return 2.
testString: 'assert.strictEqual(permAlone(''aab''), 2, ''<code>permAlone("aab")</code> should return 2.'');'
testString: 'assert.strictEqual(permAlone("aab"), 2, "<code>permAlone("aab")</code> should return 2.");'
- text: <code>permAlone("aaa")</code> should return 0.
testString: 'assert.strictEqual(permAlone(''aaa''), 0, ''<code>permAlone("aaa")</code> should return 0.'');'
testString: 'assert.strictEqual(permAlone("aaa"), 0, "<code>permAlone("aaa")</code> should return 0.");'
- text: <code>permAlone("aabb")</code> should return 8.
testString: 'assert.strictEqual(permAlone(''aabb''), 8, ''<code>permAlone("aabb")</code> should return 8.'');'
testString: 'assert.strictEqual(permAlone("aabb"), 8, "<code>permAlone("aabb")</code> should return 8.");'
- text: <code>permAlone("abcdefa")</code> should return 3600.
testString: 'assert.strictEqual(permAlone(''abcdefa''), 3600, ''<code>permAlone("abcdefa")</code> should return 3600.'');'
testString: 'assert.strictEqual(permAlone("abcdefa"), 3600, "<code>permAlone("abcdefa")</code> should return 3600.");'
- text: <code>permAlone("abfdefa")</code> should return 2640.
testString: 'assert.strictEqual(permAlone(''abfdefa''), 2640, ''<code>permAlone("abfdefa")</code> should return 2640.'');'
testString: 'assert.strictEqual(permAlone("abfdefa"), 2640, "<code>permAlone("abfdefa")</code> should return 2640.");'
- text: <code>permAlone("zzzzzzzz")</code> should return 0.
testString: 'assert.strictEqual(permAlone(''zzzzzzzz''), 0, ''<code>permAlone("zzzzzzzz")</code> should return 0.'');'
testString: 'assert.strictEqual(permAlone("zzzzzzzz"), 0, "<code>permAlone("zzzzzzzz")</code> should return 0.");'
- text: <code>permAlone("a")</code> should return 1.
testString: 'assert.strictEqual(permAlone(''a''), 1, ''<code>permAlone("a")</code> should return 1.'');'
testString: 'assert.strictEqual(permAlone("a"), 1, "<code>permAlone("a")</code> should return 1.");'
- text: <code>permAlone("aaab")</code> should return 0.
testString: 'assert.strictEqual(permAlone(''aaab''), 0, ''<code>permAlone("aaab")</code> should return 0.'');'
testString: 'assert.strictEqual(permAlone("aaab"), 0, "<code>permAlone("aaab")</code> should return 0.");'
- text: <code>permAlone("aaabb")</code> should return 12.
testString: 'assert.strictEqual(permAlone(''aaabb''), 12, ''<code>permAlone("aaabb")</code> should return 12.'');'
testString: 'assert.strictEqual(permAlone("aaabb"), 12, "<code>permAlone("aaabb")</code> should return 12.");'
```

View File

@ -26,15 +26,15 @@ Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-yo
```yml
tests:
- text: '<code>pairwise([1, 4, 2, 3, 0, 5], 7)</code> should return 11.'
testString: 'assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11, ''<code>pairwise([1, 4, 2, 3, 0, 5], 7)</code> should return 11.'');'
testString: 'assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11, "<code>pairwise([1, 4, 2, 3, 0, 5], 7)</code> should return 11.");'
- text: '<code>pairwise([1, 3, 2, 4], 4)</code> should return 1.'
testString: 'assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1, ''<code>pairwise([1, 3, 2, 4], 4)</code> should return 1.'');'
testString: 'assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1, "<code>pairwise([1, 3, 2, 4], 4)</code> should return 1.");'
- text: '<code>pairwise([1, 1, 1], 2)</code> should return 1.'
testString: 'assert.deepEqual(pairwise([1, 1, 1], 2), 1, ''<code>pairwise([1, 1, 1], 2)</code> should return 1.'');'
testString: 'assert.deepEqual(pairwise([1, 1, 1], 2), 1, "<code>pairwise([1, 1, 1], 2)</code> should return 1.");'
- text: '<code>pairwise([0, 0, 0, 0, 1, 1], 1)</code> should return 10.'
testString: 'assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10, ''<code>pairwise([0, 0, 0, 0, 1, 1], 1)</code> should return 10.'');'
testString: 'assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10, "<code>pairwise([0, 0, 0, 0, 1, 1], 1)</code> should return 10.");'
- text: '<code>pairwise([], 100)</code> should return 0.'
testString: 'assert.deepEqual(pairwise([], 100), 0, ''<code>pairwise([], 100)</code> should return 0.'');'
testString: 'assert.deepEqual(pairwise([], 100), 0, "<code>pairwise([], 100)</code> should return 0.");'
```
@ -67,7 +67,7 @@ pairwise([1,4,2,3,0,5], 7);
function pairwise(arr, arg) {
var sum = 0;
arr.forEach(function(e, i, a) {
if (e != null) {
if (e != null) {
var diff = arg-e;
a[i] = null;
var dix = a.indexOf(diff);
@ -75,7 +75,7 @@ function pairwise(arr, arg) {
sum += dix;
sum += i;
a[dix] = null;
}
}
}
});
return sum;

View File

@ -22,13 +22,13 @@ Hint: trees are naturally recursive data structures!
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>add</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.add == ''function'')})(), ''The binary search tree has a method called <code>add</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.add == "function")})(), "The binary search tree has a method called <code>add</code>.");'
- text: The add method adds elements according to the binary search tree rules.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.add !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); const expectedResult = [ 1, 4, 7, 8, 34, 45, 73, 87 ]; const result = test.inOrder(); return (expectedResult.toString() === result.toString()); })(), ''The add method adds elements according to the binary search tree rules.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.add !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); const expectedResult = [ 1, 4, 7, 8, 34, 45, 73, 87 ]; const result = test.inOrder(); return (expectedResult.toString() === result.toString()); })(), "The add method adds elements according to the binary search tree rules.");'
- text: Adding an element that already exists returns <code>null</code>
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.add !== ''function'') { return false; }; test.add(4); return test.add(4) == null; })(), ''Adding an element that already exists returns <code>null</code>'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.add !== "function") { return false; }; test.add(4); return test.add(4) == null; })(), "Adding an element that already exists returns <code>null</code>");'
```
@ -72,41 +72,41 @@ console.info('after the test');
```js
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
this.add = function (element) {
let current = this.root;
if (!current) {
this.root = new Node(element)
return;
} else {
const searchTree = function (current) {
if (current.value > element) {
if (current.left) { //si existe
return searchTree(current.left)
} else {
current.left = new Node(element);
return;
}
} else if (current.value < element) {
if (current.right) {
return searchTree(current.right)
} else {
current.right = new Node(element)
return;
}
} else {
return null;
}
}
return searchTree(current);
}
}
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
this.add = function (element) {
let current = this.root;
if (!current) {
this.root = new Node(element)
return;
} else {
const searchTree = function (current) {
if (current.value > element) {
if (current.left) { //si existe
return searchTree(current.left)
} else {
current.left = new Node(element);
return;
}
} else if (current.value < element) {
if (current.right) {
return searchTree(current.right)
} else {
current.right = new Node(element)
return;
}
} else {
return null;
}
}
return searchTree(current);
}
}
}
```

View File

@ -26,11 +26,11 @@ Remember to check if the given index is a negative or is longer than the length
```yml
tests:
- text: Your <code>addAt</code> method should reassign <code>head</code> to the new node when the given index is 0.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.addAt(0,''cat''); return test.head().element === ''cat''}()), ''Your <code>addAt</code> method should reassign <code>head</code> to the new node when the given index is 0.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.addAt(0,"cat"); return test.head().element === "cat"}()), "Your <code>addAt</code> method should reassign <code>head</code> to the new node when the given index is 0.");'
- text: Your <code>addAt</code> method should increase the length of the linked list by one for each new node added to the linked list.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.addAt(0,''cat''); return test.size() === 3}()), ''Your <code>addAt</code> method should increase the length of the linked list by one for each new node added to the linked list.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.addAt(0,"cat"); return test.size() === 3}()), "Your <code>addAt</code> method should increase the length of the linked list by one for each new node added to the linked list.");'
- text: Your <code>addAt</code> method should return <code>false</code> if a node was unable to be added.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); return (test.addAt(4,''cat'') === false); }()), ''Your <code>addAt</code> method should return <code>false</code> if a node was unable to be added.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); return (test.addAt(4,"cat") === false); }()), "Your <code>addAt</code> method should return <code>false</code> if a node was unable to be added.");'
```
@ -42,14 +42,14 @@ tests:
<div id='js-seed'>
```js
function LinkedList() {
var length = 0;
var head = null;
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){
this.element = element;
this.next = null;
};
this.element = element;
this.next = null;
};
this.size = function(){
return length;
@ -74,7 +74,7 @@ function LinkedList() {
}
length++;
};
};
// Only change code below this line

View File

@ -27,13 +27,13 @@ Create a social network as an undirected graph with 4 nodes/people named <code>J
```yml
tests:
- text: <code>undirectedAdjList</code> should only contain four nodes.
testString: 'assert(Object.keys(undirectedAdjList).length === 4, ''<code>undirectedAdjList</code> should only contain four nodes.'');'
testString: 'assert(Object.keys(undirectedAdjList).length === 4, "<code>undirectedAdjList</code> should only contain four nodes.");'
- text: There should be an edge between <code>Jeff</code> and <code>James</code>.
testString: 'assert(undirectedAdjList.James.indexOf("Jeff") !== -1 && undirectedAdjList.Jeff.indexOf("James") !== -1, ''There should be an edge between <code>Jeff</code> and <code>James</code>.'');'
testString: 'assert(undirectedAdjList.James.indexOf("Jeff") !== -1 && undirectedAdjList.Jeff.indexOf("James") !== -1, "There should be an edge between <code>Jeff</code> and <code>James</code>.");'
- text: There should be an edge between <code>Jill</code> and <code>Jenny</code>.
testString: 'assert(undirectedAdjList.Jill.indexOf("Jenny") !== -1 && undirectedAdjList.Jill.indexOf("Jenny") !== -1, ''There should be an edge between <code>Jill</code> and <code>Jenny</code>.'');'
testString: 'assert(undirectedAdjList.Jill.indexOf("Jenny") !== -1 && undirectedAdjList.Jill.indexOf("Jenny") !== -1, "There should be an edge between <code>Jill</code> and <code>Jenny</code>.");'
- text: There should be an edge between <code>Jeff</code> and <code>Jenny</code>.
testString: 'assert(undirectedAdjList.Jeff.indexOf("Jenny") !== -1 && undirectedAdjList.Jenny.indexOf("Jeff") !== -1, ''There should be an edge between <code>Jeff</code> and <code>Jenny</code>.'');'
testString: 'assert(undirectedAdjList.Jeff.indexOf("Jenny") !== -1 && undirectedAdjList.Jenny.indexOf("Jeff") !== -1, "There should be an edge between <code>Jeff</code> and <code>Jenny</code>.");'
```

View File

@ -29,15 +29,15 @@ Create an adjacency matrix of an undirected graph with five nodes. This matrix s
```yml
tests:
- text: <code>undirectedAdjList</code> should only contain five nodes.
testString: 'assert((adjMatUndirected.length === 5) && adjMatUndirected.map(function(x) { return x.length === 5 }).reduce(function(a, b) { return a && b }) , ''<code>undirectedAdjList</code> should only contain five nodes.'');'
testString: 'assert((adjMatUndirected.length === 5) && adjMatUndirected.map(function(x) { return x.length === 5 }).reduce(function(a, b) { return a && b }) , "<code>undirectedAdjList</code> should only contain five nodes.");'
- text: There should be an edge between the first and fourth node.
testString: 'assert((adjMatUndirected[0][3] === 1) && (adjMatUndirected[3][0] === 1), ''There should be an edge between the first and fourth node.'');'
testString: 'assert((adjMatUndirected[0][3] === 1) && (adjMatUndirected[3][0] === 1), "There should be an edge between the first and fourth node.");'
- text: There should be an edge between the first and third node.
testString: 'assert((adjMatUndirected[0][2] === 1) && (adjMatUndirected[2][0] === 1), ''There should be an edge between the first and third node.'');'
testString: 'assert((adjMatUndirected[0][2] === 1) && (adjMatUndirected[2][0] === 1), "There should be an edge between the first and third node.");'
- text: There should be an edge between the third and fifth node.
testString: 'assert((adjMatUndirected[2][4] === 1) && (adjMatUndirected[4][2] === 1), ''There should be an edge between the third and fifth node.'');'
testString: 'assert((adjMatUndirected[2][4] === 1) && (adjMatUndirected[4][2] === 1), "There should be an edge between the third and fifth node.");'
- text: There should be an edge between the fourth and fifth node.
testString: 'assert((adjMatUndirected[3][4] === 1) && (adjMatUndirected[4][3] === 1), ''There should be an edge between the fourth and fifth node.'');'
testString: 'assert((adjMatUndirected[3][4] === 1) && (adjMatUndirected[4][3] === 1), "There should be an edge between the fourth and fifth node.");'
```

View File

@ -29,13 +29,13 @@ Your function will output a JavaScript object key-value pairs with the node and
```yml
tests:
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return <code>{0: 1, 1: 0, 2: 1, 3: 2}</code>'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; var results = bfs(graph, 1); return isEquivalent(results, {0: 1, 1: 0, 2: 1, 3: 2})})(), ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return <code>{0: 1, 1: 0, 2: 1, 3: 2}</code>'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; var results = bfs(graph, 1); return isEquivalent(results, {0: 1, 1: 0, 2: 1, 3: 2})})(), "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return <code>{0: 1, 1: 0, 2: 1, 3: 2}</code>");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>1</code> should return <code>{0: 1, 1: 0, 2: 1, 3: Infinity}</code>'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]; var results = bfs(graph, 1); return isEquivalent(results, {0: 1, 1: 0, 2: 1, 3: Infinity})})(), ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>1</code> should return <code>{0: 1, 1: 0, 2: 1, 3: Infinity}</code>'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]; var results = bfs(graph, 1); return isEquivalent(results, {0: 1, 1: 0, 2: 1, 3: Infinity})})(), "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>1</code> should return <code>{0: 1, 1: 0, 2: 1, 3: Infinity}</code>");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return <code>{0: 0, 1: 1, 2: 2, 3: 3}</code>'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; var results = bfs(graph, 0); return isEquivalent(results, {0: 0, 1: 1, 2: 2, 3: 3})})(), ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return <code>{0: 0, 1: 1, 2: 2, 3: 3}</code>'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; var results = bfs(graph, 0); return isEquivalent(results, {0: 0, 1: 1, 2: 2, 3: 3})})(), "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return <code>{0: 0, 1: 1, 2: 2, 3: 3}</code>");'
- text: 'The input graph <code>[[0, 1], [1, 0]]</code> with a start node of <code>0</code> should return <code>{0: 0, 1: 1}</code>'
testString: 'assert((function() { var graph = [[0, 1], [1, 0]]; var results = bfs(graph, 0); return isEquivalent(results, {0: 0, 1: 1})})(), ''The input graph <code>[[0, 1], [1, 0]]</code> with a start node of <code>0</code> should return <code>{0: 0, 1: 1}</code>'');'
testString: 'assert((function() { var graph = [[0, 1], [1, 0]]; var results = bfs(graph, 0); return isEquivalent(results, {0: 0, 1: 1})})(), "The input graph <code>[[0, 1], [1, 0]]</code> with a start node of <code>0</code> should return <code>{0: 0, 1: 1}</code>");'
```
@ -50,7 +50,7 @@ tests:
function bfs(graph, root) {
// Distance object returned
var nodesLen = {};
return nodesLen;
};

View File

@ -22,13 +22,13 @@ Instructions: In this challenge, we will create a utility for our tree. Write a
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>isPresent</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.isPresent == ''function'')})(), ''The binary search tree has a method called <code>isPresent</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.isPresent == "function")})(), "The binary search tree has a method called <code>isPresent</code>.");'
- text: The <code>isPresent</code> method correctly checks for the presence or absence of elements added to the tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== ''function'') { return false; }; test.add(4); test.add(7); test.add(411); test.add(452); return ( test.isPresent(452) && test.isPresent(411) && test.isPresent(7) && !test.isPresent(100) ); })(), ''The <code>isPresent</code> method correctly checks for the presence or absence of elements added to the tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== "function") { return false; }; test.add(4); test.add(7); test.add(411); test.add(452); return ( test.isPresent(452) && test.isPresent(411) && test.isPresent(7) && !test.isPresent(100) ); })(), "The <code>isPresent</code> method correctly checks for the presence or absence of elements added to the tree.");'
- text: <code>isPresent</code> handles cases where the tree is empty.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== ''function'') { return false; }; return test.isPresent(5) == false; })(), ''<code>isPresent</code> handles cases where the tree is empty.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== "function") { return false; }; return test.isPresent(5) == false; })(), "<code>isPresent</code> handles cases where the tree is empty.");'
```
@ -46,7 +46,7 @@ function Node(value) {
this.left = null;
this.right = null;
}
function BinarySearchTree() {
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line

View File

@ -32,15 +32,15 @@ In addition, the <code>enqueue</code> method should return the item you enqueued
```yml
tests:
- text: The <code>enqueue</code> method adds items to the circular queue.
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); var print = test.print(); return print[0] === 17 && print[1] === 32 && print[2] === 591; })(), ''The <code>enqueue</code> method adds items to the circular queue.'');'
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); var print = test.print(); return print[0] === 17 && print[1] === 32 && print[2] === 591; })(), "The <code>enqueue</code> method adds items to the circular queue.");'
- text: You cannot enqueue items past the read pointer.
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); test.enqueue(13); test.enqueue(25); test.enqueue(59); var print = test.print(); return print[0] === 17 && print[1] === 32 && print[2] === 591; })(), ''You cannot enqueue items past the read pointer.'');'
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); test.enqueue(13); test.enqueue(25); test.enqueue(59); var print = test.print(); return print[0] === 17 && print[1] === 32 && print[2] === 591; })(), "You cannot enqueue items past the read pointer.");'
- text: The <code>dequeue</code> method dequeues items from the queue.
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); return test.dequeue() === 17 && test.dequeue() === 32 && test.dequeue() === 591; })(), ''The <code>dequeue</code> method dequeues items from the queue.'');'
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); return test.dequeue() === 17 && test.dequeue() === 32 && test.dequeue() === 591; })(), "The <code>dequeue</code> method dequeues items from the queue.");'
- text: After an item is dequeued its position in the queue should be reset to <code>null</code>.
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(672); test.dequeue(); test.dequeue(); var print = test.print(); return print[0] === null && print[1] === null && print[2] === 672; })(), ''After an item is dequeued its position in the queue should be reset to <code>null</code>.'');'
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(672); test.dequeue(); test.dequeue(); var print = test.print(); return print[0] === null && print[1] === null && print[2] === 672; })(), "After an item is dequeued its position in the queue should be reset to <code>null</code>.");'
- text: Trying to dequeue past the write pointer returns <code>null</code> and does not advance the write pointer.
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); return test.dequeue() === 17 && test.dequeue() === 32 && test.dequeue() === 591 && test.dequeue() === null && test.dequeue() === null && test.dequeue() === null && test.dequeue() === null && test.enqueue(100) === 100 && test.dequeue() === 100; })(), ''Trying to dequeue past the write pointer returns <code>null</code> and does not advance the write pointer.'');'
testString: 'assert((function(){ var test = new CircularQueue(3); test.enqueue(17); test.enqueue(32); test.enqueue(591); return test.dequeue() === 17 && test.dequeue() === 32 && test.dequeue() === 591 && test.dequeue() === null && test.dequeue() === null && test.dequeue() === null && test.dequeue() === null && test.enqueue(100) === 100 && test.dequeue() === 100; })(), "Trying to dequeue past the write pointer returns <code>null</code> and does not advance the write pointer.");'
```
@ -97,46 +97,46 @@ class CircularQueue {
```js
class CircularQueue {
constructor(size) {
this.queue = [];
this.read = 0;
this.write = 0;
this.max = size - 1;
while (size > 0) {
this.queue.push(null);
size--;
}
}
print() {
return this.queue;
}
enqueue(item) {
if (this.queue[this.write] === null) {
this.queue[this.write] = item;
if (this.write === this.max) {
this.write = 0;
} else {
this.write++;
}
return item;
}
return null;
}
dequeue() {
if (this.queue[this.read] !== null) {
var item = this.queue[this.read];
this.queue[this.read] = null;
if (this.read === this.max) {
this.read = 0;
} else {
this.read++;
}
return item;
} else {
return null;
}
}
class CircularQueue {
constructor(size) {
this.queue = [];
this.read = 0;
this.write = 0;
this.max = size - 1;
while (size > 0) {
this.queue.push(null);
size--;
}
}
print() {
return this.queue;
}
enqueue(item) {
if (this.queue[this.write] === null) {
this.queue[this.write] = item;
if (this.write === this.max) {
this.write = 0;
} else {
this.write++;
}
return item;
}
return null;
}
dequeue() {
if (this.queue[this.read] !== null) {
var item = this.queue[this.read];
this.queue[this.read] = null;
if (this.read === this.max) {
this.read = 0;
} else {
this.read++;
}
return item;
} else {
return null;
}
}
}
```

View File

@ -22,21 +22,21 @@ Be careful to handle any possible edge cases when writing these methods, such as
```yml
tests:
- text: The DoublyLinkedList data structure exists.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; return (typeof test == ''object'')})(), ''The DoublyLinkedList data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; return (typeof test == "object")})(), "The DoublyLinkedList data structure exists.");'
- text: The DoublyLinkedList has a method called add.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; if (test.add == undefined) { return false; }; return (typeof test.add == ''function'')})(), ''The DoublyLinkedList has a method called add.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; if (test.add == undefined) { return false; }; return (typeof test.add == "function")})(), "The DoublyLinkedList has a method called add.");'
- text: The DoublyLinkedList has a method called remove.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; if (test.remove == undefined) { return false; }; return (typeof test.remove == ''function'')})(), ''The DoublyLinkedList has a method called remove.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; if (test.remove == undefined) { return false; }; return (typeof test.remove == "function")})(), "The DoublyLinkedList has a method called remove.");'
- text: Removing an item from an empty list returns null.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; return (test.remove(100) == null); })(), ''Removing an item from an empty list returns null.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; return (test.remove(100) == null); })(), "Removing an item from an empty list returns null.");'
- text: The add method adds items to the list.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; test.add(5); test.add(6); test.add(723); return (test.print().join('''') == ''56723''); })(), ''The add method adds items to the list.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; test.add(5); test.add(6); test.add(723); return (test.print().join("") == "56723"); })(), "The add method adds items to the list.");'
- text: Each node keeps track of the previous node.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; test.add(50); test.add(68); test.add(73); return (test.printReverse().join('''') == ''736850''); })(), ''Each node keeps track of the previous node.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; test.add(50); test.add(68); test.add(73); return (test.printReverse().join("") == "736850"); })(), "Each node keeps track of the previous node.");'
- text: The first item can be removed from the list.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; test.add(25); test.add(35); test.add(60); test.remove(25); return ( test.print().join('''') == ''3560'' ) })(), ''The first item can be removed from the list.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; test.add(25); test.add(35); test.add(60); test.remove(25); return ( test.print().join("") == "3560" ) })(), "The first item can be removed from the list.");'
- text: The last item can be removed from the list.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; test.add(25); test.add(35); test.add(60); test.remove(60); return ( test.print().join('''') == ''2535'' ) })(), ''The last item can be removed from the list.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; test.add(25); test.add(35); test.add(60); test.remove(60); return ( test.print().join("") == "2535" ) })(), "The last item can be removed from the list.");'
```

View File

@ -24,21 +24,21 @@ Be sure to write your code to account for collisions!
```yml
tests:
- text: The HashTable data structure exists.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; return (typeof test === ''object'')})(), ''The HashTable data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; return (typeof test === "object")})(), "The HashTable data structure exists.");'
- text: The HashTable has an add method.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; return ((typeof test.add) === ''function'')})(), ''The HashTable has an add method.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; return ((typeof test.add) === "function")})(), "The HashTable has an add method.");'
- text: The HashTable has an remove method.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; return ((typeof test.remove) === ''function'')})(), ''The HashTable has an remove method.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; return ((typeof test.remove) === "function")})(), "The HashTable has an remove method.");'
- text: The HashTable has an lookup method.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; return ((typeof test.lookup) === ''function'')})(), ''The HashTable has an lookup method.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; return ((typeof test.lookup) === "function")})(), "The HashTable has an lookup method.");'
- text: The add method adds key value pairs and the lookup method returns the values associated with a given key.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; test.add(''key'', ''value''); return (test.lookup(''key'') === ''value'')})(), ''The add method adds key value pairs and the lookup method returns the values associated with a given key.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; test.add("key", "value"); return (test.lookup("key") === "value")})(), "The add method adds key value pairs and the lookup method returns the values associated with a given key.");'
- text: The remove method accepts a key as input and removes the associated key value pair.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; test.add(''key'', ''value''); test.remove(''key''); return (test.lookup(''key'') === null)})(), ''The remove method accepts a key as input and removes the associated key value pair.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; test.add("key", "value"); test.remove("key"); return (test.lookup("key") === null)})(), "The remove method accepts a key as input and removes the associated key value pair.");'
- text: Items are added using the hash function.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; called = 0; test.add(''key1'',''value1''); test.add(''key2'',''value2''); test.add(''key3'',''value3''); return (called === 3)})(), ''Items are added using the hash function.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; called = 0; test.add("key1","value1"); test.add("key2","value2"); test.add("key3","value3"); return (called === 3)})(), "Items are added using the hash function.");'
- text: The hash table handles collisions.
testString: 'assert((function() { var test = false; if (typeof HashTable !== ''undefined'') { test = new HashTable() }; called = 0; test.add(''key1'',''value1''); test.add(''1key'',''value2''); test.add(''ke1y'',''value3''); return (test.lookup(''key1'') === ''value1'' && test.lookup(''1key'') == ''value2'' && test.lookup(''ke1y'') == ''value3'')})(), ''The hash table handles collisions.'');'
testString: 'assert((function() { var test = false; if (typeof HashTable !== "undefined") { test = new HashTable() }; called = 0; test.add("key1","value1"); test.add("1key","value2"); test.add("ke1y","value3"); return (test.lookup("key1") === "value1" && test.lookup("1key") == "value2" && test.lookup("ke1y") == "value3")})(), "The hash table handles collisions.");'
```

View File

@ -25,13 +25,13 @@ Your list's <code>length</code> should increase by one every time an element is
```yml
tests:
- text: Your <code>LinkedList</code> class should have a <code>add</code> method.
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.add === ''function'')}()), ''Your <code>LinkedList</code> class should have a <code>add</code> method.'');'
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.add === "function")}()), "Your <code>LinkedList</code> class should have a <code>add</code> method.");'
- text: Your <code>LinkedList</code> class should assign <code>head</code> to the first node added.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); return test.head().element === ''cat''}()), ''Your <code>LinkedList</code> class should assign <code>head</code> to the first node added.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); return test.head().element === "cat"}()), "Your <code>LinkedList</code> class should assign <code>head</code> to the first node added.");'
- text: The previous <code>node</code> in your <code>LinkedList</code> class should have reference to the newest node created.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); return test.head().next.element === ''dog''}()), ''The previous <code>node</code> in your <code>LinkedList</code> class should have reference to the newest node created.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); return test.head().next.element === "dog"}()), "The previous <code>node</code> in your <code>LinkedList</code> class should have reference to the newest node created.");'
- text: The <code>size</code> of your <code>LinkedList</code> class should equal the amount of nodes in the linked list.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); return test.size() === 2}()), ''The <code>size</code> of your <code>LinkedList</code> class should equal the amount of nodes in the linked list.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); return test.size() === 2}()), "The <code>size</code> of your <code>LinkedList</code> class should equal the amount of nodes in the linked list.");'
```
@ -43,14 +43,14 @@ tests:
<div id='js-seed'>
```js
function LinkedList() {
var length = 0;
var head = null;
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){
this.element = element;
this.next = null;
};
this.element = element;
this.next = null;
};
this.head = function(){
return head;

View File

@ -31,19 +31,19 @@ Use the <code>Map</code> object provided here as a wrapper around a JavaScript <
```yml
tests:
- text: The Map data structure exists.
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; return (typeof test == ''object'')})(), ''The Map data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; return (typeof test == "object")})(), "The Map data structure exists.");'
- text: 'The Map object has the following methods: add, remove, get, has, values, clear, and size.'
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; return (typeof test.add == ''function'' && typeof test.remove == ''function'' && typeof test.get == ''function'' && typeof test.has == ''function'' && typeof test.values == ''function'' && typeof test.clear == ''function'' && typeof test.size == ''function'')})(), ''The Map object has the following methods: add, remove, get, has, values, clear, and size.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; return (typeof test.add == "function" && typeof test.remove == "function" && typeof test.get == "function" && typeof test.has == "function" && typeof test.values == "function" && typeof test.clear == "function" && typeof test.size == "function")})(), "The Map object has the following methods: add, remove, get, has, values, clear, and size.");'
- text: The add method adds items to the map.
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; test.add(5,6); test.add(2,3); test.add(2,5); return (test.size() == 2)})(), ''The add method adds items to the map.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; test.add(5,6); test.add(2,3); test.add(2,5); return (test.size() == 2)})(), "The add method adds items to the map.");'
- text: The has method returns true for added items and false for absent items.
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; test.add(''test'',''value''); return (test.has(''test'') && !test.has(''false''))})(), ''The has method returns true for added items and false for absent items.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; test.add("test","value"); return (test.has("test") && !test.has("false"))})(), "The has method returns true for added items and false for absent items.");'
- text: The get method accepts keys as input and returns the associated values.
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; test.add(''abc'',''def''); return (test.get(''abc'') == ''def'')})(), ''The get method accepts keys as input and returns the associated values.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; test.add("abc","def"); return (test.get("abc") == "def")})(), "The get method accepts keys as input and returns the associated values.");'
- text: The values method returns all the values stored in the map as strings in an array.
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; test.add(''a'',''b''); test.add(''c'',''d''); test.add(''e'',''f''); var vals = test.values(); return (vals.indexOf(''b'') != -1 && vals.indexOf(''d'') != -1 && vals.indexOf(''f'') != -1)})(), ''The values method returns all the values stored in the map as strings in an array.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; test.add("a","b"); test.add("c","d"); test.add("e","f"); var vals = test.values(); return (vals.indexOf("b") != -1 && vals.indexOf("d") != -1 && vals.indexOf("f") != -1)})(), "The values method returns all the values stored in the map as strings in an array.");'
- text: The clear method empties the map and the size method returns the number of items present in the map.
testString: 'assert((function() { var test = false; if (typeof Map !== ''undefined'') { test = new Map() }; test.add(''b'',''b''); test.add(''c'',''d''); test.remove(''asdfas''); var init = test.size(); test.clear(); return (init == 2 && test.size() == 0)})(), ''The clear method empties the map and the size method returns the number of items present in the map.'');'
testString: 'assert((function() { var test = false; if (typeof Map !== "undefined") { test = new Map() }; test.add("b","b"); test.add("c","d"); test.remove("asdfas"); var init = test.size(); test.clear(); return (init == 2 && test.size() == 0)})(), "The clear method empties the map and the size method returns the number of items present in the map.");'
```

View File

@ -26,19 +26,19 @@ The <code>enqueue</code> should accept items with the format shown above (<code>
```yml
tests:
- text: Your <code>Queue</code> class should have a <code>enqueue</code> method.
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.enqueue === ''function'')}()), ''Your <code>Queue</code> class should have a <code>enqueue</code> method.'');'
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.enqueue === "function")}()), "Your <code>Queue</code> class should have a <code>enqueue</code> method.");'
- text: Your <code>Queue</code> class should have a <code>dequeue</code> method.
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.dequeue === ''function'')}()), ''Your <code>Queue</code> class should have a <code>dequeue</code> method.'');'
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.dequeue === "function")}()), "Your <code>Queue</code> class should have a <code>dequeue</code> method.");'
- text: Your <code>Queue</code> class should have a <code>size</code> method.
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.size === ''function'')}()), ''Your <code>Queue</code> class should have a <code>size</code> method.'');'
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.size === "function")}()), "Your <code>Queue</code> class should have a <code>size</code> method.");'
- text: Your <code>Queue</code> class should have an <code>isEmpty</code> method.
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.isEmpty === ''function'')}()), ''Your <code>Queue</code> class should have an <code>isEmpty</code> method.'');'
testString: 'assert((function(){var test = new PriorityQueue(); return (typeof test.isEmpty === "function")}()), "Your <code>Queue</code> class should have an <code>isEmpty</code> method.");'
- text: Your PriorityQueue should correctly keep track of the current number of items using the <code>size</code> method as items are enqueued and dequeued.
testString: 'assert((function(){var test = new PriorityQueue(); test.enqueue([''David Brown'', 2]); test.enqueue([''Jon Snow'', 1]); var size1 = test.size(); test.dequeue(); var size2 = test.size(); test.enqueue([''A'', 3]); test.enqueue([''B'', 3]); test.enqueue([''C'', 3]); return (size1 === 2 && size2 === 1 && test.size() === 4)}()), ''Your PriorityQueue should correctly keep track of the current number of items using the <code>size</code> method as items are enqueued and dequeued.'');'
testString: 'assert((function(){var test = new PriorityQueue(); test.enqueue(["David Brown", 2]); test.enqueue(["Jon Snow", 1]); var size1 = test.size(); test.dequeue(); var size2 = test.size(); test.enqueue(["A", 3]); test.enqueue(["B", 3]); test.enqueue(["C", 3]); return (size1 === 2 && size2 === 1 && test.size() === 4)}()), "Your PriorityQueue should correctly keep track of the current number of items using the <code>size</code> method as items are enqueued and dequeued.");'
- text: The <code>isEmpty</code> method should return <code>true</code> when the queue is empty.
testString: 'assert((function(){var test = new PriorityQueue(); test.enqueue([''A'', 1]); test.enqueue([''B'', 1]); test.dequeue(); var first = test.isEmpty(); test.dequeue(); return (!first && test.isEmpty()); }()), ''The <code>isEmpty</code> method should return <code>true</code> when the queue is empty.'');'
testString: 'assert((function(){var test = new PriorityQueue(); test.enqueue(["A", 1]); test.enqueue(["B", 1]); test.dequeue(); var first = test.isEmpty(); test.dequeue(); return (!first && test.isEmpty()); }()), "The <code>isEmpty</code> method should return <code>true</code> when the queue is empty.");'
- text: The priority queue should return items with a higher priority before items with a lower priority and return items in first-in-first-out order otherwise.
testString: 'assert((function(){var test = new PriorityQueue(); test.enqueue([''A'', 5]); test.enqueue([''B'', 5]); test.enqueue([''C'', 5]); test.enqueue([''D'', 3]); test.enqueue([''E'', 1]); test.enqueue([''F'', 7]); var result = []; result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); return result.join('''') === ''EDABCF'';}()), ''The priority queue should return items with a higher priority before items with a lower priority and return items in first-in-first-out order otherwise.'');'
testString: 'assert((function(){var test = new PriorityQueue(); test.enqueue(["A", 5]); test.enqueue(["B", 5]); test.enqueue(["C", 5]); test.enqueue(["D", 3]); test.enqueue(["E", 1]); test.enqueue(["F", 7]); var result = []; result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); result.push(test.dequeue()); return result.join("") === "EDABCF";}()), "The priority queue should return items with a higher priority before items with a lower priority and return items in first-in-first-out order otherwise.");'
```
@ -72,17 +72,17 @@ function PriorityQueue () {
```js
function PriorityQueue () {
this.collection = [];
this.printCollection = function(){
console.log(this.collection);
};
this.size = function() {
return this.collection.length;
};
this.isEmpty = function() {
return this.size() > 0 ? false : true;
};
function PriorityQueue () {
this.collection = [];
this.printCollection = function(){
console.log(this.collection);
};
this.size = function() {
return this.collection.length;
};
this.isEmpty = function() {
return this.size() > 0 ? false : true;
};
this.enqueue = function (newitem) {
if (this.isEmpty()) {
return this.collection.push(newitem);
@ -98,14 +98,14 @@ function PriorityQueue () {
this.collection.splice(found_index, 0, newitem);
}
this.collection = this.collection.reverse();
};
this.dequeue = function() {
if (!this.isEmpty()) {
return this.collection.shift()[0];
} else {
return 'The queue is empty.'
}
};
};
this.dequeue = function() {
if (!this.isEmpty()) {
return this.collection.shift()[0];
} else {
return 'The queue is empty.'
}
};
}
```

View File

@ -24,23 +24,23 @@ Write an enqueue method that pushes an element to the tail of the queue, a deque
```yml
tests:
- text: Your <code>Queue</code> class should have a <code>enqueue</code> method.
testString: 'assert((function(){var test = new Queue(); return (typeof test.enqueue === ''function'')}()), ''Your <code>Queue</code> class should have a <code>enqueue</code> method.'');'
testString: 'assert((function(){var test = new Queue(); return (typeof test.enqueue === "function")}()), "Your <code>Queue</code> class should have a <code>enqueue</code> method.");'
- text: Your <code>Queue</code> class should have a <code>dequeue</code> method.
testString: 'assert((function(){var test = new Queue(); return (typeof test.dequeue === ''function'')}()), ''Your <code>Queue</code> class should have a <code>dequeue</code> method.'');'
testString: 'assert((function(){var test = new Queue(); return (typeof test.dequeue === "function")}()), "Your <code>Queue</code> class should have a <code>dequeue</code> method.");'
- text: Your <code>Queue</code> class should have a <code>front</code> method.
testString: 'assert((function(){var test = new Queue(); return (typeof test.front === ''function'')}()), ''Your <code>Queue</code> class should have a <code>front</code> method.'');'
testString: 'assert((function(){var test = new Queue(); return (typeof test.front === "function")}()), "Your <code>Queue</code> class should have a <code>front</code> method.");'
- text: Your <code>Queue</code> class should have a <code>size</code> method.
testString: 'assert((function(){var test = new Queue(); return (typeof test.size === ''function'')}()), ''Your <code>Queue</code> class should have a <code>size</code> method.'');'
testString: 'assert((function(){var test = new Queue(); return (typeof test.size === "function")}()), "Your <code>Queue</code> class should have a <code>size</code> method.");'
- text: Your <code>Queue</code> class should have an <code>isEmpty</code> method.
testString: 'assert((function(){var test = new Queue(); return (typeof test.isEmpty === ''function'')}()), ''Your <code>Queue</code> class should have an <code>isEmpty</code> method.'');'
testString: 'assert((function(){var test = new Queue(); return (typeof test.isEmpty === "function")}()), "Your <code>Queue</code> class should have an <code>isEmpty</code> method.");'
- text: The <code>dequeue</code> method should remove and return the front element of the queue
testString: 'assert((function(){var test = new Queue(); test.enqueue(''Smith''); return (test.dequeue() === ''Smith'')}()), ''The <code>dequeue</code> method should remove and return the front element of the queue'');'
testString: 'assert((function(){var test = new Queue(); test.enqueue("Smith"); return (test.dequeue() === "Smith")}()), "The <code>dequeue</code> method should remove and return the front element of the queue");'
- text: The <code>front</code> method should return value of the front element of the queue
testString: 'assert((function(){var test = new Queue(); test.enqueue(''Smith''); test.enqueue(''John''); return (test.front() === ''Smith'')}()), ''The <code>front</code> method should return value of the front element of the queue'');'
testString: 'assert((function(){var test = new Queue(); test.enqueue("Smith"); test.enqueue("John"); return (test.front() === "Smith")}()), "The <code>front</code> method should return value of the front element of the queue");'
- text: The <code>size</code> method should return the length of the queue
testString: 'assert((function(){var test = new Queue(); test.enqueue(''Smith''); return (test.size() === 1)}()), ''The <code>size</code> method should return the length of the queue'');'
testString: 'assert((function(){var test = new Queue(); test.enqueue("Smith"); return (test.size() === 1)}()), "The <code>size</code> method should return the length of the queue");'
- text: The <code>isEmpty</code> method should return <code>false</code> if there are elements in the queue
testString: 'assert((function(){var test = new Queue(); test.enqueue(''Smith''); return !(test.isEmpty())}()), ''The <code>isEmpty</code> method should return <code>false</code> if there are elements in the queue'');'
testString: 'assert((function(){var test = new Queue(); test.enqueue("Smith"); return !(test.isEmpty())}()), "The <code>isEmpty</code> method should return <code>false</code> if there are elements in the queue");'
```
@ -52,7 +52,7 @@ tests:
<div id='js-seed'>
```js
function Queue () {
function Queue () {
var collection = [];
this.print = function() {
console.log(collection);

View File

@ -25,13 +25,13 @@ The function should return <code>true</code> if the value is successfully added
```yml
tests:
- text: Your <code>Set</code> class should have an <code>add</code> method.
testString: 'assert((function(){var test = new Set(); return (typeof test.add === ''function'')}()), ''Your <code>Set</code> class should have an <code>add</code> method.'');'
testString: 'assert((function(){var test = new Set(); return (typeof test.add === "function")}()), "Your <code>Set</code> class should have an <code>add</code> method.");'
- text: Your <code>add</code> method should not add duplicate values.
testString: 'assert((function(){var test = new Set(); test.add(''a''); test.add(''b''); test.add(''a''); var vals = test.values(); return (vals[0] === ''a'' && vals[1] === ''b'' && vals.length === 2)}()), ''Your <code>add</code> method should not add duplicate values.'');'
testString: 'assert((function(){var test = new Set(); test.add("a"); test.add("b"); test.add("a"); var vals = test.values(); return (vals[0] === "a" && vals[1] === "b" && vals.length === 2)}()), "Your <code>add</code> method should not add duplicate values.");'
- text: Your <code>add</code> method should return <code>true</code> when a value has been successfully added.
testString: 'assert((function(){var test = new Set(); var result = test.add(''a''); return (result != undefined) && (result === true);}()), ''Your <code>add</code> method should return <code>true</code> when a value has been successfully added.'');'
testString: 'assert((function(){var test = new Set(); var result = test.add("a"); return (result != undefined) && (result === true);}()), "Your <code>add</code> method should return <code>true</code> when a value has been successfully added.");'
- text: Your <code>add</code> method should return <code>false</code> when a duplicate value is added.
testString: 'assert((function(){var test = new Set(); test.add(''a''); var result = test.add(''a''); return (result != undefined) && (result === false);}()), ''Your <code>add</code> method should return <code>false</code> when a duplicate value is added.'');'
testString: 'assert((function(){var test = new Set(); test.add("a"); var result = test.add("a"); return (result != undefined) && (result === false);}()), "Your <code>add</code> method should return <code>false</code> when a duplicate value is added.");'
```

View File

@ -25,23 +25,23 @@ Normally stacks don't have this, but we've added a <code>print</code> helper met
```yml
tests:
- text: Your <code>Stack</code> class should have a <code>push</code> method.
testString: 'assert((function(){var test = new Stack(); return (typeof test.push === ''function'')}()), ''Your <code>Stack</code> class should have a <code>push</code> method.'');'
testString: 'assert((function(){var test = new Stack(); return (typeof test.push === "function")}()), "Your <code>Stack</code> class should have a <code>push</code> method.");'
- text: Your <code>Stack</code> class should have a <code>pop</code> method.
testString: 'assert((function(){var test = new Stack(); return (typeof test.pop === ''function'')}()), ''Your <code>Stack</code> class should have a <code>pop</code> method.'');'
testString: 'assert((function(){var test = new Stack(); return (typeof test.pop === "function")}()), "Your <code>Stack</code> class should have a <code>pop</code> method.");'
- text: Your <code>Stack</code> class should have a <code>peek</code> method.
testString: 'assert((function(){var test = new Stack(); return (typeof test.peek === ''function'')}()), ''Your <code>Stack</code> class should have a <code>peek</code> method.'');'
testString: 'assert((function(){var test = new Stack(); return (typeof test.peek === "function")}()), "Your <code>Stack</code> class should have a <code>peek</code> method.");'
- text: Your <code>Stack</code> class should have a <code>isEmpty</code> method.
testString: 'assert((function(){var test = new Stack(); return (typeof test.isEmpty === ''function'')}()), ''Your <code>Stack</code> class should have a <code>isEmpty</code> method.'');'
testString: 'assert((function(){var test = new Stack(); return (typeof test.isEmpty === "function")}()), "Your <code>Stack</code> class should have a <code>isEmpty</code> method.");'
- text: Your <code>Stack</code> class should have a <code>clear</code> method.
testString: 'assert((function(){var test = new Stack(); return (typeof test.clear === ''function'')}()), ''Your <code>Stack</code> class should have a <code>clear</code> method.'');'
testString: 'assert((function(){var test = new Stack(); return (typeof test.clear === "function")}()), "Your <code>Stack</code> class should have a <code>clear</code> method.");'
- text: The <code>peek</code> method should return the top element of the stack
testString: 'assert((function(){var test = new Stack(); test.push(''CS50''); return (test.peek() === ''CS50'')}()), ''The <code>peek</code> method should return the top element of the stack'');'
testString: 'assert((function(){var test = new Stack(); test.push("CS50"); return (test.peek() === "CS50")}()), "The <code>peek</code> method should return the top element of the stack");'
- text: The <code>pop</code> method should remove and return the top element of the stack
testString: 'assert((function(){var test = new Stack(); test.push(''CS50''); return (test.pop() === ''CS50'');}()), ''The <code>pop</code> method should remove and return the top element of the stack'');'
testString: 'assert((function(){var test = new Stack(); test.push("CS50"); return (test.pop() === "CS50");}()), "The <code>pop</code> method should remove and return the top element of the stack");'
- text: The <code>isEmpty</code> method should return true if a stack does not contain any elements
testString: 'assert((function(){var test = new Stack(); return test.isEmpty()}()), ''The <code>isEmpty</code> method should return true if a stack does not contain any elements'');'
testString: 'assert((function(){var test = new Stack(); return test.isEmpty()}()), "The <code>isEmpty</code> method should return true if a stack does not contain any elements");'
- text: The <code>clear</code> method should remove all element from the stack
testString: 'assert((function(){var test = new Stack(); test.push(''CS50''); test.clear(); return (test.isEmpty())}()), ''The <code>clear</code> method should remove all element from the stack'');'
testString: 'assert((function(){var test = new Stack(); test.push("CS50"); test.clear(); return (test.isEmpty())}()), "The <code>clear</code> method should remove all element from the stack");'
```
@ -53,7 +53,7 @@ tests:
<div id='js-seed'>
```js
function Stack() {
function Stack() {
var collection = [];
this.print = function() {
console.log(collection);

View File

@ -24,15 +24,15 @@ In order for us to verify that this data structure is implemented correctly, we'
```yml
tests:
- text: The Trie has an add method.
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== ''undefined'') { test = new Trie() } else { return false; }; return (typeof test.add == ''function'') }()), ''The Trie has an add method.'');'
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== "undefined") { test = new Trie() } else { return false; }; return (typeof test.add == "function") }()), "The Trie has an add method.");'
- text: The Trie has a print method.
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== ''undefined'') { test = new Trie() } else { return false; }; return (typeof test.print == ''function'') }()), ''The Trie has a print method.'');'
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== "undefined") { test = new Trie() } else { return false; }; return (typeof test.print == "function") }()), "The Trie has a print method.");'
- text: The Trie has an isWord method.
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== ''undefined'') { test = new Trie() } else { return false; }; return (typeof test.isWord == ''function'') }()), ''The Trie has an isWord method.'');'
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== "undefined") { test = new Trie() } else { return false; }; return (typeof test.isWord == "function") }()), "The Trie has an isWord method.");'
- text: The print method returns all items added to the trie as strings in an array.
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== ''undefined'') { test = new Trie() } else { return false; }; test.add(''jump''); test.add(''jumps''); test.add(''jumped''); test.add(''house''); test.add(''mouse''); var added = test.print(); return (added.indexOf(''jump'') != -1 && added.indexOf(''jumps'') != -1 && added.indexOf(''jumped'') != -1 && added.indexOf(''house'') != -1 && added.indexOf(''mouse'') != -1 && added.length == 5); }()), ''The print method returns all items added to the trie as strings in an array.'');'
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== "undefined") { test = new Trie() } else { return false; }; test.add("jump"); test.add("jumps"); test.add("jumped"); test.add("house"); test.add("mouse"); var added = test.print(); return (added.indexOf("jump") != -1 && added.indexOf("jumps") != -1 && added.indexOf("jumped") != -1 && added.indexOf("house") != -1 && added.indexOf("mouse") != -1 && added.length == 5); }()), "The print method returns all items added to the trie as strings in an array.");'
- text: The isWord method returns true only for words added to the trie and false for all other words.
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== ''undefined'') { test = new Trie() } else { return false; }; test.add(''hop''); test.add(''hops''); test.add(''hopped''); test.add(''hoppy''); test.add(''hope''); return (test.isWord(''hop'') && !test.isWord(''ho'') && test.isWord(''hopped'') && !test.isWord(''hopp'') && test.isWord(''hoppy'') && !test.isWord(''hoping'')); }()), ''The isWord method returns true only for words added to the trie and false for all other words.'');'
testString: 'assert((function testTrie() { var test = false; if (typeof Trie !== "undefined") { test = new Trie() } else { return false; }; test.add("hop"); test.add("hops"); test.add("hopped"); test.add("hoppy"); test.add("hope"); return (test.isWord("hop") && !test.isWord("ho") && test.isWord("hopped") && !test.isWord("hopp") && test.isWord("hoppy") && !test.isWord("hoping")); }()), "The isWord method returns true only for words added to the trie and false for all other words.");'
```

View File

@ -28,9 +28,9 @@ Instructions: Define a JavaScript Map object and assign to it a variable called
```yml
tests:
- text: The myMap object exists.
testString: 'assert(typeof myMap === ''object'', ''The myMap object exists.'');'
testString: 'assert(typeof myMap === "object", "The myMap object exists.");'
- text: 'myMap contains the key value pair <code>freeCodeCamp</code>, <code>Awesome!</code>.'
testString: 'assert(myMap.get(''freeCodeCamp'') === ''Awesome!'', ''myMap contains the key value pair <code>freeCodeCamp</code>, <code>Awesome!</code>.'');'
testString: 'assert(myMap.get("freeCodeCamp") === "Awesome!", "myMap contains the key value pair <code>freeCodeCamp</code>, <code>Awesome!</code>.");'
```

View File

@ -30,7 +30,7 @@ For this exercise, return a set with the following values: <code>1, 2, 3, 'Taco'
```yml
tests:
- text: 'Your <code>Set</code> should only contain the values <code>1, 2, 3, Taco, Cat, Awesome</code>.'
testString: 'assert(function(){var test = checkSet(); return (test.size == 6) && test.has(1) && test.has(2) && test.has(3) && test.has(''Taco'') && test.has(''Cat'') && test.has(''Awesome'');}, ''Your <code>Set</code> should only contain the values <code>1, 2, 3, Taco, Cat, Awesome</code>.'');'
testString: 'assert(function(){var test = checkSet(); return (test.size == 6) && test.has(1) && test.has(2) && test.has(3) && test.has("Taco") && test.has("Cat") && test.has("Awesome");}, "Your <code>Set</code> should only contain the values <code>1, 2, 3, Taco, Cat, Awesome</code>.");'
```
@ -45,7 +45,7 @@ tests:
function checkSet() {
var set = new Set([1, 2, 3, 3, 2, 1, 2, 3, 1]);
// change code below this line
// change code above this line
console.log(set);
return set;

View File

@ -26,15 +26,15 @@ We will handle the second and third cases in the next challenges. Good luck!
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>remove</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == ''function'')})(), ''The binary search tree has a method called <code>remove</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == "function")})(), "The binary search tree has a method called <code>remove</code>.");'
- text: Trying to remove an element that does not exist returns <code>null</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; return (test.remove(100) == null); })(), ''Trying to remove an element that does not exist returns <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; return (test.remove(100) == null); })(), "Trying to remove an element that does not exist returns <code>null</code>.");'
- text: 'If the root node has no children, deleting it sets the root to <code>null</code>.'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(500); test.remove(500); return (test.inorder() == null); })(), ''If the root node has no children, deleting it sets the root to <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(500); test.remove(500); return (test.inorder() == null); })(), "If the root node has no children, deleting it sets the root to <code>null</code>.");'
- text: The <code>remove</code> method removes leaf nodes from the tree
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (test.inorder().join('''') == ''567''); })(), ''The <code>remove</code> method removes leaf nodes from the tree'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (test.inorder().join("") == "567"); })(), "The <code>remove</code> method removes leaf nodes from the tree");'
```

View File

@ -21,19 +21,19 @@ Instructions: We've provided some code in our <code>remove</code> method that ac
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>remove</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == ''function'')})(), ''The binary search tree has a method called <code>remove</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == "function")})(), "The binary search tree has a method called <code>remove</code>.");'
- text: Trying to remove an element that does not exist returns <code>null</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; return (test.remove(100) == null); })(), ''Trying to remove an element that does not exist returns <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; return (test.remove(100) == null); })(), "Trying to remove an element that does not exist returns <code>null</code>.");'
- text: 'If the root node has no children, deleting it sets the root to <code>null</code>.'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(500); test.remove(500); return (test.inorder() == null); })(), ''If the root node has no children, deleting it sets the root to <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(500); test.remove(500); return (test.inorder() == null); })(), "If the root node has no children, deleting it sets the root to <code>null</code>.");'
- text: The <code>remove</code> method removes leaf nodes from the tree
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (test.inorder().join('''') == ''567''); })(), ''The <code>remove</code> method removes leaf nodes from the tree'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (test.inorder().join("") == "567"); })(), "The <code>remove</code> method removes leaf nodes from the tree");'
- text: The <code>remove</code> method removes nodes with one child.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(-1); test.add(3); test.add(7); test.add(16); test.remove(16); test.remove(7); test.remove(3); return (test.inorder().join('''') == ''-1''); })(), ''The <code>remove</code> method removes nodes with one child.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(-1); test.add(3); test.add(7); test.add(16); test.remove(16); test.remove(7); test.remove(3); return (test.inorder().join("") == "-1"); })(), "The <code>remove</code> method removes nodes with one child.");'
- text: Removing the root in a tree with two nodes sets the second to be the root.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(15); test.add(27); test.remove(15); return (test.inorder().join('''') == ''27''); })(), ''Removing the root in a tree with two nodes sets the second to be the root.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(15); test.add(27); test.remove(15); return (test.inorder().join("") == "27"); })(), "Removing the root in a tree with two nodes sets the second to be the root.");'
```

View File

@ -22,23 +22,23 @@ Instructions: Let's finish our <code>remove</code> method by handling the third
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>remove</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == ''function'')})(), ''The binary search tree has a method called <code>remove</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == "function")})(), "The binary search tree has a method called <code>remove</code>.");'
- text: Trying to remove an element that does not exist returns <code>null</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == ''function'') ? (test.remove(100) == null) : false})(), ''Trying to remove an element that does not exist returns <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == "function") ? (test.remove(100) == null) : false})(), "Trying to remove an element that does not exist returns <code>null</code>.");'
- text: 'If the root node has no children, deleting it sets the root to <code>null</code>.'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; test.add(500); test.remove(500); return (typeof test.remove == ''function'') ? (test.inorder() == null) : false})(), ''If the root node has no children, deleting it sets the root to <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; test.add(500); test.remove(500); return (typeof test.remove == "function") ? (test.inorder() == null) : false})(), "If the root node has no children, deleting it sets the root to <code>null</code>.");'
- text: The <code>remove</code> method removes leaf nodes from the tree
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (typeof test.remove == ''function'') ? (test.inorder().join('''') == ''567'') : false})(), ''The <code>remove</code> method removes leaf nodes from the tree'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (typeof test.remove == "function") ? (test.inorder().join("") == "567") : false})(), "The <code>remove</code> method removes leaf nodes from the tree");'
- text: The <code>remove</code> method removes nodes with one child.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(-1); test.add(3); test.add(7); test.add(16); test.remove(16); test.remove(7); test.remove(3); return (test.inorder().join('''') == ''-1''); })(), ''The <code>remove</code> method removes nodes with one child.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(-1); test.add(3); test.add(7); test.add(16); test.remove(16); test.remove(7); test.remove(3); return (test.inorder().join("") == "-1"); })(), "The <code>remove</code> method removes nodes with one child.");'
- text: Removing the root in a tree with two nodes sets the second to be the root.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(15); test.add(27); test.remove(15); return (test.inorder().join('''') == ''27''); })(), ''Removing the root in a tree with two nodes sets the second to be the root.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(15); test.add(27); test.remove(15); return (test.inorder().join("") == "27"); })(), "Removing the root in a tree with two nodes sets the second to be the root.");'
- text: The <code>remove</code> method removes nodes with two children while maintaining the binary search tree structure.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(1); test.add(4); test.add(3); test.add(7); test.add(9); test.add(11); test.add(14); test.add(15); test.add(19); test.add(50); test.remove(9); if (!test.isBinarySearchTree()) { return false; }; test.remove(11); if (!test.isBinarySearchTree()) { return false; }; test.remove(14); if (!test.isBinarySearchTree()) { return false; }; test.remove(19); if (!test.isBinarySearchTree()) { return false; }; test.remove(3); if (!test.isBinarySearchTree()) { return false; }; test.remove(50); if (!test.isBinarySearchTree()) { return false; }; test.remove(15); if (!test.isBinarySearchTree()) { return false; }; return (test.inorder().join('''') == ''147''); })(), ''The <code>remove</code> method removes nodes with two children while maintaining the binary search tree structure.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(1); test.add(4); test.add(3); test.add(7); test.add(9); test.add(11); test.add(14); test.add(15); test.add(19); test.add(50); test.remove(9); if (!test.isBinarySearchTree()) { return false; }; test.remove(11); if (!test.isBinarySearchTree()) { return false; }; test.remove(14); if (!test.isBinarySearchTree()) { return false; }; test.remove(19); if (!test.isBinarySearchTree()) { return false; }; test.remove(3); if (!test.isBinarySearchTree()) { return false; }; test.remove(50); if (!test.isBinarySearchTree()) { return false; }; test.remove(15); if (!test.isBinarySearchTree()) { return false; }; return (test.inorder().join("") == "147"); })(), "The <code>remove</code> method removes nodes with two children while maintaining the binary search tree structure.");'
- text: The root can be removed on a tree of three nodes.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== ''function'') { return false; }; test.add(100); test.add(50); test.add(300); test.remove(100); return (test.inorder().join('''') == 50300); })(), ''The root can be removed on a tree of three nodes.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== "function") { return false; }; test.add(100); test.add(50); test.add(300); test.remove(100); return (test.inorder().join("") == 50300); })(), "The root can be removed on a tree of three nodes.");'
```

View File

@ -26,21 +26,21 @@ Your function should output an array of all nodes reachable from <code>root</cod
```yml
tests:
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return an array with <code>0</code>, <code>1</code>, <code>2</code>, and <code>3</code>.'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 1);})(), [0, 1, 2, 3], ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return an array with <code>0</code>, <code>1</code>, <code>2</code>, and <code>3</code>.'');'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 1);})(), [0, 1, 2, 3], "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return an array with <code>0</code>, <code>1</code>, <code>2</code>, and <code>3</code>.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return an array with four elements.'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 1);})().length === 4, ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return an array with four elements.'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 1);})().length === 4, "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>1</code> should return an array with four elements.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>3</code> should return an array with <code>3</code>.'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]; return dfs(graph, 3);})(), [3], ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>3</code> should return an array with <code>3</code>.'');'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]; return dfs(graph, 3);})(), [3], "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>3</code> should return an array with <code>3</code>.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>3</code> should return an array with one element.'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]; return dfs(graph, 3);})().length === 1, ''The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>3</code> should return an array with one element.'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]; return dfs(graph, 3);})().length === 1, "The input graph <code>[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]</code> with a start node of <code>3</code> should return an array with one element.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>3</code> should return an array with <code>2</code> and <code>3</code>.'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 3);})(), [2, 3], ''The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>3</code> should return an array with <code>2</code> and <code>3</code>.'');'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 3);})(), [2, 3], "The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>3</code> should return an array with <code>2</code> and <code>3</code>.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>3</code> should return an array with two elements.'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 3);})().length === 2, ''The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>3</code> should return an array with two elements.'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 3);})().length === 2, "The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>3</code> should return an array with two elements.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return an array with <code>0</code> and <code>1</code>.'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 0);})(), [0, 1], ''The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return an array with <code>0</code> and <code>1</code>.'');'
testString: 'assert.sameMembers((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 0);})(), [0, 1], "The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return an array with <code>0</code> and <code>1</code>.");'
- text: 'The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return an array with two elements.'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 0);})().length === 2, ''The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return an array with two elements.'');'
testString: 'assert((function() { var graph = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]; return dfs(graph, 0);})().length === 2, "The input graph <code>[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]</code> with a start node of <code>0</code> should return an array with two elements.");'
```
@ -53,7 +53,7 @@ tests:
```js
function dfs(graph, root) {
}
var exDFSGraph = [

View File

@ -23,21 +23,21 @@ Instructions: Write two methods for our binary tree: <code>findMinHeight</code>
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>findMinHeight</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMinHeight == ''function'')})(), ''The binary search tree has a method called <code>findMinHeight</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMinHeight == "function")})(), "The binary search tree has a method called <code>findMinHeight</code>.");'
- text: The binary search tree has a method called <code>findMaxHeight</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMaxHeight == ''function'')})(), ''The binary search tree has a method called <code>findMaxHeight</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMaxHeight == "function")})(), "The binary search tree has a method called <code>findMaxHeight</code>.");'
- text: The binary search tree has a method called <code>isBalanced</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.isBalanced == ''function'')})(), ''The binary search tree has a method called <code>isBalanced</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.isBalanced == "function")})(), "The binary search tree has a method called <code>isBalanced</code>.");'
- text: The <code>findMinHeight</code> method returns the minimum height of the tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMinHeight !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return (test.findMinHeight() == 1); })(), ''The <code>findMinHeight</code> method returns the minimum height of the tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMinHeight !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return (test.findMinHeight() == 1); })(), "The <code>findMinHeight</code> method returns the minimum height of the tree.");'
- text: The <code>findMaxHeight</code> method returns the maximum height of the tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMaxHeight !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return (test.findMaxHeight() == 5); })(), ''The <code>findMaxHeight</code> method returns the maximum height of the tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMaxHeight !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return (test.findMaxHeight() == 5); })(), "The <code>findMaxHeight</code> method returns the maximum height of the tree.");'
- text: An empty tree returns a height of <code>-1</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMaxHeight !== ''function'') { return false; }; return (test.findMaxHeight() == -1); })(), ''An empty tree returns a height of <code>-1</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMaxHeight !== "function") { return false; }; return (test.findMaxHeight() == -1); })(), "An empty tree returns a height of <code>-1</code>.");'
- text: The <code>isBalanced</code> method returns true if the tree is a balanced binary search tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.isBalanced !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.isBalanced(); })(), ''The <code>isBalanced</code> method returns true if the tree is a balanced binary search tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.isBalanced !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.isBalanced(); })(), "The <code>isBalanced</code> method returns true if the tree is a balanced binary search tree.");'
```

View File

@ -26,17 +26,17 @@ Instructions: We'll start simple. We've defined the skeleton of a binary search
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>findMin</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMin == ''function'')})(), ''The binary search tree has a method called <code>findMin</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMin == "function")})(), "The binary search tree has a method called <code>findMin</code>.");'
- text: The binary search tree has a method called <code>findMax</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMax == ''function'')})(), ''The binary search tree has a method called <code>findMax</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMax == "function")})(), "The binary search tree has a method called <code>findMax</code>.");'
- text: The <code>findMin</code> method returns the minimum value in the binary search tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMin !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.findMin() == 1; })(), ''The <code>findMin</code> method returns the minimum value in the binary search tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMin !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.findMin() == 1; })(), "The <code>findMin</code> method returns the minimum value in the binary search tree.");'
- text: The <code>findMax</code> method returns the maximum value in the binary search tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMax !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.findMax() == 87; })(), ''The <code>findMax</code> method returns the maximum value in the binary search tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMax !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.findMax() == 87; })(), "The <code>findMax</code> method returns the maximum value in the binary search tree.");'
- text: The <code>findMin</code> and <code>findMax</code> methods return <code>null</code> for an empty tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMin !== ''function'') { return false; }; if (typeof test.findMax !== ''function'') { return false; }; return (test.findMin() == null && test.findMax() == null) })(), ''The <code>findMin</code> and <code>findMax</code> methods return <code>null</code> for an empty tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMin !== "function") { return false; }; if (typeof test.findMax !== "function") { return false; }; return (test.findMin() == null && test.findMax() == null) })(), "The <code>findMin</code> and <code>findMax</code> methods return <code>null</code> for an empty tree.");'
```

View File

@ -22,15 +22,15 @@ Instructions: Let's implement heap sort with a min heap. Feel free to adapt your
```yml
tests:
- text: The MinHeap data structure exists.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== ''undefined'') { test = new MinHeap() }; return (typeof test == ''object'')})(), ''The MinHeap data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() }; return (typeof test == "object")})(), "The MinHeap data structure exists.");'
- text: MinHeap has a method called insert.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== ''undefined'') { test = new MinHeap() } else { return false; }; return (typeof test.insert == ''function'')})(), ''MinHeap has a method called insert.'');'
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; return (typeof test.insert == "function")})(), "MinHeap has a method called insert.");'
- text: MinHeap has a method called remove.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== ''undefined'') { test = new MinHeap() } else { return false; }; return (typeof test.remove == ''function'')})(), ''MinHeap has a method called remove.'');'
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; return (typeof test.remove == "function")})(), "MinHeap has a method called remove.");'
- text: MinHeap has a method called sort.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== ''undefined'') { test = new MinHeap() } else { return false; }; return (typeof test.sort == ''function'')})(), ''MinHeap has a method called sort.'');'
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; return (typeof test.sort == "function")})(), "MinHeap has a method called sort.");'
- text: The sort method returns an array containing all items added to the min heap in sorted order.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== ''undefined'') { test = new MinHeap() } else { return false; }; test.insert(3); test.insert(12); test.insert(5); test.insert(10); test.insert(1); test.insert(27); test.insert(42); test.insert(57); test.insert(5); var result = test.sort(); return (isSorted(result)); })(), ''The sort method returns an array containing all items added to the min heap in sorted order.'');'
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; test.insert(3); test.insert(12); test.insert(5); test.insert(10); test.insert(1); test.insert(27); test.insert(42); test.insert(57); test.insert(5); var result = test.sort(); return (isSorted(result)); })(), "The sort method returns an array containing all items added to the min heap in sorted order.");'
```

View File

@ -32,15 +32,15 @@ These five nodes have relationships following relationships. The first edge is b
```yml
tests:
- text: <code>incMatUndirected</code> should only contain five nodes.
testString: 'assert((incMatUndirected.length === 5) && incMatUndirected.map(function(x) { return x.length === 4 }).reduce(function(a, b) { return a && b }) , ''<code>incMatUndirected</code> should only contain five nodes.'');'
testString: 'assert((incMatUndirected.length === 5) && incMatUndirected.map(function(x) { return x.length === 4 }).reduce(function(a, b) { return a && b }) , "<code>incMatUndirected</code> should only contain five nodes.");'
- text: There should be a first edge between the first and second node.
testString: 'assert((incMatUndirected[0][0] === 1) && (incMatUndirected[1][0] === 1), ''There should be a first edge between the first and second node.'');'
testString: 'assert((incMatUndirected[0][0] === 1) && (incMatUndirected[1][0] === 1), "There should be a first edge between the first and second node.");'
- text: There should be a second edge between the second and third node.
testString: 'assert((incMatUndirected[1][1] === 1) && (incMatUndirected[2][1] === 1), ''There should be a second edge between the second and third node.'');'
testString: 'assert((incMatUndirected[1][1] === 1) && (incMatUndirected[2][1] === 1), "There should be a second edge between the second and third node.");'
- text: There should be a third edge between the third and fifth node.
testString: 'assert((incMatUndirected[2][2] === 1) && (incMatUndirected[4][2] === 1), ''There should be a third edge between the third and fifth node.'');'
testString: 'assert((incMatUndirected[2][2] === 1) && (incMatUndirected[4][2] === 1), "There should be a third edge between the third and fifth node.");'
- text: There should be a fourth edge between the second and fourth node.
testString: 'assert((incMatUndirected[1][3] === 1) && (incMatUndirected[3][3] === 1), ''There should be a fourth edge between the second and fourth node.'');'
testString: 'assert((incMatUndirected[1][3] === 1) && (incMatUndirected[3][3] === 1), "There should be a fourth edge between the second and fourth node.");'
```
@ -53,7 +53,7 @@ tests:
```js
var incMatUndirected = [
];
```

View File

@ -35,13 +35,13 @@ Finally, add a print method which returns an array of all the items that have be
```yml
tests:
- text: The MaxHeap data structure exists.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() }; return (typeof test == ''object'')})(), ''The MaxHeap data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() }; return (typeof test == "object")})(), "The MaxHeap data structure exists.");'
- text: MaxHeap has a method called insert.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; return (typeof test.insert == ''function'')})(), ''MaxHeap has a method called insert.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; return (typeof test.insert == "function")})(), "MaxHeap has a method called insert.");'
- text: MaxHeap has a method called print.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; return (typeof test.print == ''function'')})(), ''MaxHeap has a method called print.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; return (typeof test.print == "function")})(), "MaxHeap has a method called print.");'
- text: The insert method adds elements according to the max heap property.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; test.insert(50); test.insert(100); test.insert(700); test.insert(32); test.insert(51); let result = test.print(); return ((result.length == 5) ? result[0] == 700 : result[1] == 700) })(), ''The insert method adds elements according to the max heap property.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; test.insert(50); test.insert(100); test.insert(700); test.insert(32); test.insert(51); let result = test.print(); return ((result.length == 5) ? result[0] == 700 : result[1] == 700) })(), "The insert method adds elements according to the max heap property.");'
```

View File

@ -20,13 +20,13 @@ Here will we create a function to invert a binary tree. Given a binary tree, we
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>invert</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.invert == ''function'')})(), ''The binary search tree has a method called <code>invert</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.invert == "function")})(), "The binary search tree has a method called <code>invert</code>.");'
- text: The <code>invert</code> method correctly inverts the tree structure.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.invert !== ''function'') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); test.invert(); return test.inorder().join('''') == ''877345348741''; })(), ''The <code>invert</code> method correctly inverts the tree structure.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.invert !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); test.invert(); return test.inorder().join("") == "877345348741"; })(), "The <code>invert</code> method correctly inverts the tree structure.");'
- text: Inverting an empty tree returns <code>null</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.invert !== ''function'') { return false; }; return (test.invert() == null); })(), ''Inverting an empty tree returns <code>null</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.invert !== "function") { return false; }; return (test.invert() == null); })(), "Inverting an empty tree returns <code>null</code>.");'
```

View File

@ -25,13 +25,13 @@ Modify the given array and treat it like a <code>stack</code> using the JavaScri
```yml
tests:
- text: <code>homeworkStack</code> should only contain 4 elements.
testString: 'assert(homeworkStack.length === 4, ''<code>homeworkStack</code> should only contain 4 elements.'');'
testString: 'assert(homeworkStack.length === 4, "<code>homeworkStack</code> should only contain 4 elements.");'
- text: The last element in <code>homeworkStack</code> should be <code>"CS50"</code>.
testString: 'assert(homeworkStack[3] === ''CS50'', ''The last element in <code>homeworkStack</code> should be <code>"CS50"</code>.'');'
testString: 'assert(homeworkStack[3] === "CS50", "The last element in <code>homeworkStack</code> should be <code>"CS50"</code>.");'
- text: <code>homeworkStack</code> should not contain <code>"PSY44"</code>.
testString: 'assert(homeworkStack.indexOf(''PSY44'') === -1, ''<code>homeworkStack</code> should not contain <code>"PSY44"</code>.'');'
testString: 'assert(homeworkStack.indexOf("PSY44") === -1, "<code>homeworkStack</code> should not contain <code>"PSY44"</code>.");'
- text: The initial declaration of the <code>homeworkStack</code> should not be changed.
testString: 'assert(code.match(/=/g).length === 1 && /homeworkStack\s*=\s*\["BIO12"\s*,\s*"HIS80"\s*,\s*"MAT122"\s*,\s*"PSY44"\]/.test(code), ''The initial declaration of the <code>homeworkStack</code> should not be changed.'');'
testString: 'assert(code.match(/=/g).length === 1 && /homeworkStack\s*=\s*\["BIO12"\s*,\s*"HIS80"\s*,\s*"MAT122"\s*,\s*"PSY44"\]/.test(code), "The initial declaration of the <code>homeworkStack</code> should not be changed.");'
```

View File

@ -21,9 +21,9 @@ For example, if <code>setA = ['a','b','c']</code> and <code>setB = ['a','b','d',
```yml
tests:
- text: Your <code>Set</code> class should have a <code>difference</code> method.
testString: 'assert(function(){var test = new Set(); return (typeof test.difference === ''function'')}, ''Your <code>Set</code> class should have a <code>difference</code> method.'');'
testString: 'assert(function(){var test = new Set(); return (typeof test.difference === "function")}, "Your <code>Set</code> class should have a <code>difference</code> method.");'
- text: The proper collection was returned
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add(''a''); setA.add(''b''); setA.add(''c''); setB.add(''c''); setB.add(''d''); var differenceSetAB = setA.difference(setB); return (differenceSetAB.size() === 2) && (differenceSetAB.values() === [ ''a'', ''b'' ])}, ''The proper collection was returned'');'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add("a"); setA.add("b"); setA.add("c"); setB.add("c"); setB.add("d"); var differenceSetAB = setA.difference(setB); return (differenceSetAB.size() === 2) && (differenceSetAB.values() === [ "a", "b" ])}, "The proper collection was returned");'
```

View File

@ -21,17 +21,17 @@ For example, if <code>setA = ['a','b']</code> and <code>setB = ['a','b','c','d']
```yml
tests:
- text: Your <code>Set</code> class should have a <code>union</code> method.
testString: 'assert(function(){var test = new Set(); return (typeof test.subset === ''function'')}, ''Your <code>Set</code> class should have a <code>union</code> method.'');'
testString: 'assert(function(){var test = new Set(); return (typeof test.subset === "function")}, "Your <code>Set</code> class should have a <code>union</code> method.");'
- text: The first Set() was contained in the second Set
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add(''a''); setB.add(''b''); setB.add(''c''); setB.add(''a''); setB.add(''d''); var subsetSetAB = setA.subset(setB);return (subsetSetAB === true)}, ''The first Set() was contained in the second Set'');'
- text: '<code>[''a'', ''b''].subset([''a'', ''b'', ''c'', ''d''])</code> should return <code>true</code>")'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add(''a''); setA.add(''b''); setB.add(''a''); setB.add(''b''); setB.add(''c''); setB.add(''d''); var subsetSetAB = setA.subset(setB); return (subsetSetAB === true)}, "<code>[''a'', ''b''].subset([''a'', ''b'', ''c'', ''d''])</code> should return <code>true</code>");'
- text: '<code>[''a'', ''b'', ''c''].subset([''a'', ''b''])</code> should return <code>false</code>")'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add(''a''); setA.add(''b''); setA.add(''c''); setB.add(''a''); setB.add(''b''); var subsetSetAB = setA.subset(setB); return (subsetSetAB === false)}, "<code>[''a'', ''b'', ''c''].subset([''a'', ''b''])</code> should return <code>false</code>");'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add("a"); setB.add("b"); setB.add("c"); setB.add("a"); setB.add("d"); var subsetSetAB = setA.subset(setB);return (subsetSetAB === true)}, "The first Set() was contained in the second Set");'
- text: '<code>["a", "b"].subset(["a", "b", "c", "d"])</code> should return <code>true</code>")'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add("a"); setA.add("b"); setB.add("a"); setB.add("b"); setB.add("c"); setB.add("d"); var subsetSetAB = setA.subset(setB); return (subsetSetAB === true)}, "<code>["a", "b"].subset(["a", "b", "c", "d"])</code> should return <code>true</code>");'
- text: '<code>["a", "b", "c"].subset(["a", "b"])</code> should return <code>false</code>")'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add("a"); setA.add("b"); setA.add("c"); setB.add("a"); setB.add("b"); var subsetSetAB = setA.subset(setB); return (subsetSetAB === false)}, "<code>["a", "b", "c"].subset(["a", "b"])</code> should return <code>false</code>");'
- text: '<code>[].subset([])</code> should return <code>true</code>'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); var subsetSetAB = setA.subset(setB); return (subsetSetAB === true)}, ''<code>[].subset([])</code> should return <code>true</code>'');'
- text: '<code>[''a'', ''b''].subset([''c'', ''d''])</code> should return <code>false</code>")'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add(''a''); setA.add(''b''); setB.add(''c''); setB.add(''d''); var subsetSetAB = setA.subset(setB); return (subsetSetAB === false)}, "<code>[''a'', ''b''].subset([''c'', ''d''])</code> should return <code>false</code>");'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); var subsetSetAB = setA.subset(setB); return (subsetSetAB === true)}, "<code>[].subset([])</code> should return <code>true</code>");'
- text: '<code>["a", "b"].subset(["c", "d"])</code> should return <code>false</code>")'
testString: 'assert(function(){var setA = new Set(); var setB = new Set(); setA.add("a"); setA.add("b"); setB.add("c"); setB.add("d"); var subsetSetAB = setA.subset(setB); return (subsetSetAB === false)}, "<code>["a", "b"].subset(["c", "d"])</code> should return <code>false</code>");'
```

View File

@ -21,9 +21,9 @@ For example, if <code>setA = ['a','b','c']</code> and <code>setB = ['a','b','d',
```yml
tests:
- text: Your <code>Set</code> class should have a <code>union</code> method.
testString: 'assert((function(){var test = new Set(); return (typeof test.union === ''function'')})(), ''Your <code>Set</code> class should have a <code>union</code> method.'');'
testString: 'assert((function(){var test = new Set(); return (typeof test.union === "function")})(), "Your <code>Set</code> class should have a <code>union</code> method.");'
- text: The proper collection was returned
testString: 'assert((function(){var setA = new Set(); var setB = new Set(); setA.add(''a''); setA.add(''b''); setA.add(''c''); setB.add(''c''); setB.add(''d''); var unionSetAB = setA.union(setB); var final = unionSetAB.values(); return (final.indexOf(''a'') !== -1 && final.indexOf(''b'') !== -1 && final.indexOf(''c'') !== -1 && final.indexOf(''d'') !== -1 && final.length === 4)})(), ''The proper collection was returned'');'
testString: 'assert((function(){var setA = new Set(); var setB = new Set(); setA.add("a"); setA.add("b"); setA.add("c"); setB.add("c"); setB.add("d"); var unionSetAB = setA.union(setB); var final = unionSetAB.values(); return (final.indexOf("a") !== -1 && final.indexOf("b") !== -1 && final.indexOf("c") !== -1 && final.indexOf("d") !== -1 && final.length === 4)})(), "The proper collection was returned");'
```

View File

@ -21,9 +21,9 @@ For example, if <code>setA = ['a','b','c']</code> and <code>setB = ['a','b','d',
```yml
tests:
- text: Your <code>Set</code> class should have a <code>intersection</code> method.
testString: 'assert(function(){var test = new Set(); return (typeof test.intersection === ''function'')}, ''Your <code>Set</code> class should have a <code>intersection</code> method.'');'
testString: 'assert(function(){var test = new Set(); return (typeof test.intersection === "function")}, "Your <code>Set</code> class should have a <code>intersection</code> method.");'
- text: The proper collection was returned
testString: 'assert(function(){ var setA = new Set(); var setB = new Set(); setA.add(''a''); setA.add(''b''); setA.add(''c''); setB.add(''c''); setB.add(''d''); var intersectionSetAB = setA.intersection(setB); return (intersectionSetAB.size() === 1 && intersectionSetAB.values()[0] === ''c'')}, ''The proper collection was returned'');'
testString: 'assert(function(){ var setA = new Set(); var setB = new Set(); setA.add("a"); setA.add("b"); setA.add("c"); setB.add("c"); setB.add("d"); var intersectionSetAB = setA.intersection(setB); return (intersectionSetAB.size() === 1 && intersectionSetAB.values()[0] === "c")}, "The proper collection was returned");'
```

View File

@ -24,15 +24,15 @@ Instructions: Add a method to our max heap called remove. This method should ret
```yml
tests:
- text: The MaxHeap data structure exists.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() }; return (typeof test == ''object'')})(), ''The MaxHeap data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() }; return (typeof test == "object")})(), "The MaxHeap data structure exists.");'
- text: MaxHeap has a method called print.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; return (typeof test.print == ''function'')})(), ''MaxHeap has a method called print.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; return (typeof test.print == "function")})(), "MaxHeap has a method called print.");'
- text: MaxHeap has a method called insert.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; return (typeof test.insert == ''function'')})(), ''MaxHeap has a method called insert.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; return (typeof test.insert == "function")})(), "MaxHeap has a method called insert.");'
- text: MaxHeap has a method called remove.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; return (typeof test.remove == ''function'')})(), ''MaxHeap has a method called remove.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; return (typeof test.remove == "function")})(), "MaxHeap has a method called remove.");'
- text: The remove method removes the greatest element from the max heap while maintaining the max heap property.
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== ''undefined'') { test = new MaxHeap() } else { return false; }; test.insert(30); test.insert(300); test.insert(500); test.insert(10); let result = []; result.push(test.remove()); result.push(test.remove()); result.push(test.remove()); result.push(test.remove()); return (result.join('''') == ''5003003010'') })(), ''The remove method removes the greatest element from the max heap while maintaining the max heap property.'');'
testString: 'assert((function() { var test = false; if (typeof MaxHeap !== "undefined") { test = new MaxHeap() } else { return false; }; test.insert(30); test.insert(300); test.insert(500); test.insert(10); let result = []; result.push(test.remove()); result.push(test.remove()); result.push(test.remove()); result.push(test.remove()); return (result.join("") == "5003003010") })(), "The remove method removes the greatest element from the max heap while maintaining the max heap property.");'
```

View File

@ -25,15 +25,15 @@ Remember to keep count of the <code>currentIndex</code>.
```yml
tests:
- text: Your <code>LinkedList</code> class should have a <code>removeAt</code> method.
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.removeAt === ''function'')}()), ''Your <code>LinkedList</code> class should have a <code>removeAt</code> method.'');'
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.removeAt === "function")}()), "Your <code>LinkedList</code> class should have a <code>removeAt</code> method.");'
- text: Your <code>removeAt</code> method should reduce the <code>length</code> of the linked list
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); test.removeAt(1); return test.size() === 2}()), ''Your <code>removeAt</code> method should reduce the <code>length</code> of the linked list'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); test.removeAt(1); return test.size() === 2}()), "Your <code>removeAt</code> method should reduce the <code>length</code> of the linked list");'
- text: Your <code>removeAt</code> method should also return the element of the removed node.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); return test.removeAt(1) === ''dog''}()), ''Your <code>removeAt</code> method should also return the element of the removed node.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); return test.removeAt(1) === "dog"}()), "Your <code>removeAt</code> method should also return the element of the removed node.");'
- text: Your <code>removeAt</code> method should also return <code>null</code> if the given index is less than <code>0</code>
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); return (test.removeAt(-1) === null)}()), ''Your <code>removeAt</code> method should also return <code>null</code> if the given index is less than <code>0</code>'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); return (test.removeAt(-1) === null)}()), "Your <code>removeAt</code> method should also return <code>null</code> if the given index is less than <code>0</code>");'
- text: Your <code>removeAt</code> method should also return <code>null</code> if the given index is equal or more than the <code>length</code> of the linked list.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); return (test.removeAt(3) === null)}()), ''Your <code>removeAt</code> method should also return <code>null</code> if the given index is equal or more than the <code>length</code> of the linked list.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); return (test.removeAt(3) === null)}()), "Your <code>removeAt</code> method should also return <code>null</code> if the given index is equal or more than the <code>length</code> of the linked list.");'
```
@ -45,14 +45,14 @@ tests:
<div id='js-seed'>
```js
function LinkedList() {
var length = 0;
var head = null;
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){ // {1}
this.element = element;
this.next = null;
};
var Node = function(element){ // {1}
this.element = element;
this.next = null;
};
this.size = function(){
return length;
@ -77,7 +77,7 @@ function LinkedList() {
}
length++;
};
};
this.remove = function(element){
var currentNode = head;

View File

@ -25,13 +25,13 @@ The <code>length</code> of the list should decrease by one every time an element
```yml
tests:
- text: Your <code>LinkedList</code> class should have a <code>remove</code> method.
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.remove === ''function'')}()), ''Your <code>LinkedList</code> class should have a <code>remove</code> method.'');'
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.remove === "function")}()), "Your <code>LinkedList</code> class should have a <code>remove</code> method.");'
- text: Your <code>remove</code> method should reassign <code>head</code> to the second node when the first node is removed.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.remove(''cat''); return test.head().element === ''dog''}()), ''Your <code>remove</code> method should reassign <code>head</code> to the second node when the first node is removed.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.remove("cat"); return test.head().element === "dog"}()), "Your <code>remove</code> method should reassign <code>head</code> to the second node when the first node is removed.");'
- text: Your <code>remove</code> method should decrease the <code>length</code> of the linked list by one for every node removed.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.remove(''cat''); return test.size() === 1})(), ''Your <code>remove</code> method should decrease the <code>length</code> of the linked list by one for every node removed.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.remove("cat"); return test.size() === 1})(), "Your <code>remove</code> method should decrease the <code>length</code> of the linked list by one for every node removed.");'
- text: Your <code>remove</code> method should reassign the reference of the previous node of the removed node to the removed node&apos;s <code>next</code> reference.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog'');test.add(''kitten''); test.remove(''dog''); return test.head().next.element === ''kitten''})(), ''Your <code>remove</code> method should reassign the reference of the previous node of the removed node to the removed node&apos;s <code>next</code> reference.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog");test.add("kitten"); test.remove("dog"); return test.head().next.element === "kitten"})(), "Your <code>remove</code> method should reassign the reference of the previous node of the removed node to the removed node&apos;s <code>next</code> reference.");'
```
@ -43,14 +43,14 @@ tests:
<div id='js-seed'>
```js
function LinkedList() {
var length = 0;
var head = null;
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){
this.element = element;
this.next = null;
};
var Node = function(element){
this.element = element;
this.next = null;
};
this.size = function(){
return length;
@ -75,7 +75,7 @@ function LinkedList() {
}
length++;
};
};
this.remove = function(element){
// Only change code below this line
@ -129,29 +129,29 @@ class LinkedList {
current = current.next;
}
current.next = node;
current.next = node;
}
++this._length;
}
remove (element) {
if (this._head === null) return;
let previous;
let current = this._head;
while (current.next !== null && current.element !== element) {
previous = current;
current = current.next;
}
if (previous) {
previous.next = current.next;
} else {
this._head = current.next;
}
--this._length;
}
}

View File

@ -20,11 +20,11 @@ In this exercises we are going to create a delete function for our set. The func
```yml
tests:
- text: Your <code>Set</code> class should have a <code>remove</code> method.
testString: 'assert((function(){var test = new Set(); return (typeof test.remove === ''function'')}()), ''Your <code>Set</code> class should have a <code>remove</code> method.'');'
testString: 'assert((function(){var test = new Set(); return (typeof test.remove === "function")}()), "Your <code>Set</code> class should have a <code>remove</code> method.");'
- text: Your <code>remove</code> method should only remove items that are present in the set.
testString: 'assert.deepEqual((function(){var test = new Set(); test.add(''a'');test.add(''b'');test.remove(''c''); return test.values(); })(), [''a'', ''b''], ''Your <code>remove</code> method should only remove items that are present in the set.'');'
testString: 'assert.deepEqual((function(){var test = new Set(); test.add("a");test.add("b");test.remove("c"); return test.values(); })(), ["a", "b"], "Your <code>remove</code> method should only remove items that are present in the set.");'
- text: Your <code>remove</code> method should remove the given item from the set.
testString: 'assert((function(){var test = new Set(); test.add(''a'');test.add(''b'');test.remove(''a''); var vals = test.values(); return (vals[0] === ''b'' && vals.length === 1)}()), ''Your <code>remove</code> method should remove the given item from the set.'');'
testString: 'assert((function(){var test = new Set(); test.add("a");test.add("b");test.remove("a"); var vals = test.values(); return (vals[0] === "b" && vals.length === 1)}()), "Your <code>remove</code> method should remove the given item from the set.");'
```

View File

@ -15,7 +15,7 @@ Now remove an item from your Set with the <code>delete</code> method.
## Instructions
<section id='instructions'>
Now, create a set with the integers 1, 2, 3, 4, & 5.
Now, create a set with the integers 1, 2, 3, 4, & 5.
Remove the values 2 and 5, and then return the set.
</section>
@ -25,7 +25,7 @@ Now, create a set with the integers 1, 2, 3, 4, & 5.
```yml
tests:
- text: 'Your Set should contain the values 1, 3, & 4'
testString: 'assert(function(){var test = checkSet(); return test.has(1) && test.has(3) && test.has(4) && test.size === 3}, ''Your Set should contain the values 1, 3, & 4'');'
testString: 'assert(function(){var test = checkSet(); return test.has(1) && test.has(3) && test.has(4) && test.size === 3}, "Your Set should contain the values 1, 3, & 4");'
```

View File

@ -20,17 +20,17 @@ Let's create one more method for our doubly linked list called reverse which rev
```yml
tests:
- text: The DoublyLinkedList data structure exists.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; return (typeof test == ''object'')})(), ''The DoublyLinkedList data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; return (typeof test == "object")})(), "The DoublyLinkedList data structure exists.");'
- text: The DoublyLinkedList has a method called add.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; if (test.add == undefined) { return false; }; return (typeof test.add == ''function'')})(), ''The DoublyLinkedList has a method called add.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; if (test.add == undefined) { return false; }; return (typeof test.add == "function")})(), "The DoublyLinkedList has a method called add.");'
- text: The DoublyLinkedList has a method called reverse.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; if (test.reverse == undefined) { return false; }; return (typeof test.reverse == ''function'')})(), ''The DoublyLinkedList has a method called reverse.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; if (test.reverse == undefined) { return false; }; return (typeof test.reverse == "function")})(), "The DoublyLinkedList has a method called reverse.");'
- text: Reversing an empty list returns null.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; return (test.reverse() == null); })(), ''Reversing an empty list returns null.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; return (test.reverse() == null); })(), "Reversing an empty list returns null.");'
- text: The reverse method reverses the list.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; test.add(58); test.add(61); test.add(32); test.reverse(); return (test.print().join('''') == ''326158''); })(), ''The reverse method reverses the list.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; test.add(58); test.add(61); test.add(32); test.reverse(); return (test.print().join("") == "326158"); })(), "The reverse method reverses the list.");'
- text: The next and previous references are correctly maintained when a list is reversed.
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== ''undefined'') { test = new DoublyLinkedList() }; test.add(11); test.add(22); test.add(33); test.reverse(); return (test.printReverse().join('''') == ''112233''); })(), ''The next and previous references are correctly maintained when a list is reversed.'');'
testString: 'assert((function() { var test = false; if (typeof DoublyLinkedList !== "undefined") { test = new DoublyLinkedList() }; test.add(11); test.add(22); test.add(33); test.reverse(); return (test.printReverse().join("") == "112233"); })(), "The next and previous references are correctly maintained when a list is reversed.");'
```

View File

@ -22,15 +22,15 @@ Write an <code>isEmpty</code> method that checks if the linked list is empty, an
```yml
tests:
- text: Your <code>LinkedList</code> class should have a <code>indexOf</code> method.
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.indexOf === ''function'')}()), ''Your <code>LinkedList</code> class should have a <code>indexOf</code> method.'');'
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.indexOf === "function")}()), "Your <code>LinkedList</code> class should have a <code>indexOf</code> method.");'
- text: Your <code>LinkedList</code> class should have a <code>elementAt</code> method.
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.elementAt === ''function'')}()), ''Your <code>LinkedList</code> class should have a <code>elementAt</code> method.'');'
testString: 'assert((function(){var test = new LinkedList(); return (typeof test.elementAt === "function")}()), "Your <code>LinkedList</code> class should have a <code>elementAt</code> method.");'
- text: Your <code>size</code> method should return the length of the linked list
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); return test.size() === 3}()), ''Your <code>size</code> method should return the length of the linked list'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); return test.size() === 3}()), "Your <code>size</code> method should return the length of the linked list");'
- text: Your <code>indexOf</code> method should return the index of the given element.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); return test.indexOf(''kitten'') === 2}()), ''Your <code>indexOf</code> method should return the index of the given element.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); return test.indexOf("kitten") === 2}()), "Your <code>indexOf</code> method should return the index of the given element.");'
- text: Your <code>elementAt</code> method should return at element at a given index.
testString: 'assert((function(){var test = new LinkedList(); test.add(''cat''); test.add(''dog''); test.add(''kitten''); return test.elementAt(1) === ''dog''}()), ''Your <code>elementAt</code> method should return at element at a given index.'');'
testString: 'assert((function(){var test = new LinkedList(); test.add("cat"); test.add("dog"); test.add("kitten"); return test.elementAt(1) === "dog"}()), "Your <code>elementAt</code> method should return at element at a given index.");'
```
@ -42,14 +42,14 @@ tests:
<div id='js-seed'>
```js
function LinkedList() {
var length = 0;
var head = null;
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){ // {1}
this.element = element;
this.next = null;
};
var Node = function(element){ // {1}
this.element = element;
this.next = null;
};
this.size = function() {
return length;
@ -74,7 +74,7 @@ function LinkedList() {
}
length++;
};
};
this.remove = function(element){
var currentNode = head;

View File

@ -20,9 +20,9 @@ In this exercise we are going to create a size function for our Set. This functi
```yml
tests:
- text: Your <code>Set</code> class should have a <code>size</code> method.
testString: 'assert((function(){var test = new Set(); return (typeof test.size === ''function'')}()), ''Your <code>Set</code> class should have a <code>size</code> method.'');'
testString: 'assert((function(){var test = new Set(); return (typeof test.size === "function")}()), "Your <code>Set</code> class should have a <code>size</code> method.");'
- text: The <code>size</code> method should return the number of elements in the collection.
testString: 'assert((function(){var test = new Set(); test.add(''a'');test.add(''b'');test.remove(''a'');return (test.size() === 1)}()), ''The <code>size</code> method should return the number of elements in the collection.'');'
testString: 'assert((function(){var test = new Set(); test.add("a");test.add("b");test.remove("a");return (test.size() === 1)}()), "The <code>size</code> method should return the number of elements in the collection.");'
```

View File

@ -33,11 +33,11 @@ First create a <code>buffer</code> that is 64-bytes. Then create a <code>Int32Ar
```yml
tests:
- text: Your <code>buffer</code> should be 64 bytes large.
testString: 'assert(buffer.byteLength === 64, ''Your <code>buffer</code> should be 64 bytes large.'');'
testString: 'assert(buffer.byteLength === 64, "Your <code>buffer</code> should be 64 bytes large.");'
- text: Your <code>i32View</code> view of your buffer should be 64 bytes large.
testString: 'assert(i32View.byteLength === 64, ''Your <code>i32View</code> view of your buffer should be 64 bytes large.'');'
testString: 'assert(i32View.byteLength === 64, "Your <code>i32View</code> view of your buffer should be 64 bytes large.");'
- text: Your <code>i32View</code> view of your buffer should be 16 elements long.
testString: 'assert(i32View.length === 16, ''Your <code>i32View</code> view of your buffer should be 16 elements long.'');'
testString: 'assert(i32View.length === 16, "Your <code>i32View</code> view of your buffer should be 16 elements long.");'
```

View File

@ -26,7 +26,7 @@ In this exercise we will pass an array and a value to the checkSet() function. Y
```yml
tests:
- text: '<code>checkSet([4, 5, 6], 3)</code> should return [ false, 3 ]'
testString: 'assert(function(){var test = checkSet([4,5,6], 3); test === [ false, 3 ]}, ''<code>checkSet([4, 5, 6], 3)</code> should return [ false, 3 ]'');'
testString: 'assert(function(){var test = checkSet([4,5,6], 3); test === [ false, 3 ]}, "<code>checkSet([4, 5, 6], 3)</code> should return [ false, 3 ]");'
```

View File

@ -22,19 +22,19 @@ Instructions: Let's create a breadth-first search method in our tree called <cod
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>levelOrder</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.levelOrder == ''function'')})(), ''The binary search tree has a method called <code>levelOrder</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.levelOrder == "function")})(), "The binary search tree has a method called <code>levelOrder</code>.");'
- text: The binary search tree has a method called <code>reverseLevelOrder</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.reverseLevelOrder == ''function'')})(), ''The binary search tree has a method called <code>reverseLevelOrder</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.reverseLevelOrder == "function")})(), "The binary search tree has a method called <code>reverseLevelOrder</code>.");'
- text: The <code>levelOrder</code> method returns an array of the tree node values explored in level order.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.levelOrder !== ''function'') { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.levelOrder().join('''') == ''719038102546''); })(), ''The <code>levelOrder</code> method returns an array of the tree node values explored in level order.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.levelOrder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.levelOrder().join("") == "719038102546"); })(), "The <code>levelOrder</code> method returns an array of the tree node values explored in level order.");'
- text: The <code>reverseLevelOrder</code> method returns an array of the tree node values explored in reverse level order.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== ''function'') { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.reverseLevelOrder().join('''') == ''791108305264''); })(), ''The <code>reverseLevelOrder</code> method returns an array of the tree node values explored in reverse level order.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.reverseLevelOrder().join("") == "791108305264"); })(), "The <code>reverseLevelOrder</code> method returns an array of the tree node values explored in reverse level order.");'
- text: The <code>levelOrder</code> method returns <code>null</code> for an empty tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.levelOrder !== ''function'') { return false; }; return (test.levelOrder() == null); })(), ''The <code>levelOrder</code> method returns <code>null</code> for an empty tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.levelOrder !== "function") { return false; }; return (test.levelOrder() == null); })(), "The <code>levelOrder</code> method returns <code>null</code> for an empty tree.");'
- text: The <code>reverseLevelOrder</code> method returns <code>null</code> for an empty tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== ''function'') { return false; }; return (test.reverseLevelOrder() == null); })(), ''The <code>reverseLevelOrder</code> method returns <code>null</code> for an empty tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== "function") { return false; }; return (test.reverseLevelOrder() == null); })(), "The <code>reverseLevelOrder</code> method returns <code>null</code> for an empty tree.");'
```

View File

@ -26,25 +26,25 @@ Define <code>inorder</code>, <code>preorder</code>, and <code>postorder</code> m
```yml
tests:
- text: The <code>BinarySearchTree</code> data structure exists.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() }; return (typeof test == ''object'')})(), ''The <code>BinarySearchTree</code> data structure exists.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The <code>BinarySearchTree</code> data structure exists.");'
- text: The binary search tree has a method called <code>inorder</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.inorder == ''function'')})(), ''The binary search tree has a method called <code>inorder</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.inorder == "function")})(), "The binary search tree has a method called <code>inorder</code>.");'
- text: The binary search tree has a method called <code>preorder</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.preorder == ''function'')})(), ''The binary search tree has a method called <code>preorder</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.preorder == "function")})(), "The binary search tree has a method called <code>preorder</code>.");'
- text: The binary search tree has a method called <code>postorder</code>.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.postorder == ''function'')})(), ''The binary search tree has a method called <code>postorder</code>.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.postorder == "function")})(), "The binary search tree has a method called <code>postorder</code>.");'
- text: The <code>inorder</code> method returns an array of the node values that result from an inorder traversal.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.inorder !== ''function'') { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.inorder().join('''') == ''012345678910''); })(), ''The <code>inorder</code> method returns an array of the node values that result from an inorder traversal.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.inorder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.inorder().join("") == "012345678910"); })(), "The <code>inorder</code> method returns an array of the node values that result from an inorder traversal.");'
- text: The <code>preorder</code> method returns an array of the node values that result from a preorder traversal.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.preorder !== ''function'') { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.preorder().join('''') == ''710325469810''); })(), ''The <code>preorder</code> method returns an array of the node values that result from a preorder traversal.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.preorder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.preorder().join("") == "710325469810"); })(), "The <code>preorder</code> method returns an array of the node values that result from a preorder traversal.");'
- text: The <code>postorder</code> method returns an array of the node values that result from a postorder traversal.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.postorder !== ''function'') { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.postorder().join('''') == ''024653181097''); })(), ''The <code>postorder</code> method returns an array of the node values that result from a postorder traversal.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.postorder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.postorder().join("") == "024653181097"); })(), "The <code>postorder</code> method returns an array of the node values that result from a postorder traversal.");'
- text: The <code>inorder</code> method returns <code>null</code> for an empty tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.inorder !== ''function'') { return false; }; return (test.inorder() == null); })(), ''The <code>inorder</code> method returns <code>null</code> for an empty tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.inorder !== "function") { return false; }; return (test.inorder() == null); })(), "The <code>inorder</code> method returns <code>null</code> for an empty tree.");'
- text: The <code>preorder</code> method returns <code>null</code> for an empty tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.preorder !== ''function'') { return false; }; return (test.preorder() == null); })(), ''The <code>preorder</code> method returns <code>null</code> for an empty tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.preorder !== "function") { return false; }; return (test.preorder() == null); })(), "The <code>preorder</code> method returns <code>null</code> for an empty tree.");'
- text: The <code>postorder</code> method returns <code>null</code> for an empty tree.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; if (typeof test.postorder !== ''function'') { return false; }; return (test.postorder() == null); })(), ''The <code>postorder</code> method returns <code>null</code> for an empty tree.'');'
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.postorder !== "function") { return false; }; return (test.postorder() == null); })(), "The <code>postorder</code> method returns <code>null</code> for an empty tree.");'
```

View File

@ -24,7 +24,7 @@ Now you've successfully learned how to use the ES6 <code>Set()</code> object, go
```yml
tests:
- text: Your Set was returned correctly!
testString: 'assert(function(){var test = checkSet(new Set([1,2,3,4,5,6,7])); test === [ 1, 2, 3, 4, 5, 6, 7 ]}, ''Your Set was returned correctly!'');'
testString: 'assert(function(){var test = checkSet(new Set([1,2,3,4,5,6,7])); test === [ 1, 2, 3, 4, 5, 6, 7 ]}, "Your Set was returned correctly!");'
```

View File

@ -22,9 +22,9 @@ Create a <code>Cat</code> and <code>Dog</code> node and manually add them to the
```yml
tests:
- text: Your <code>Puppy</code> node should have a reference to a <code>Cat</code> node.
testString: 'assert(Puppy.next.element === "Cat", ''Your <code>Puppy</code> node should have a reference to a <code>Cat</code> node.'');'
testString: 'assert(Puppy.next.element === "Cat", "Your <code>Puppy</code> node should have a reference to a <code>Cat</code> node.");'
- text: Your <code>Cat</code> node should have a reference to a <code>Dog</code> node.
testString: 'assert(Cat.next.element === "Dog", ''Your <code>Cat</code> node should have a reference to a <code>Dog</code> node.'');'
testString: 'assert(Cat.next.element === "Dog", "Your <code>Cat</code> node should have a reference to a <code>Dog</code> node.");'
```
@ -37,8 +37,8 @@ tests:
```js
var Node = function(element){
this.element = element;
this.next = null;
this.element = element;
this.next = null;
};
var Kitten = new Node("Kitten");
var Puppy = new Node("Puppy");

View File

@ -21,13 +21,13 @@ Find the sum of all the multiples of 3 or 5 below the provided parameter value <
```yml
tests:
- text: <code>multiplesOf3and5(1000)</code> should return 233168.
testString: 'assert.strictEqual(multiplesOf3and5(1000), 233168, ''<code>multiplesOf3and5(1000)</code> should return 233168.'');'
testString: 'assert.strictEqual(multiplesOf3and5(1000), 233168, "<code>multiplesOf3and5(1000)</code> should return 233168.");'
- text: <code>multiplesOf3and5(49)</code> should return 543.
testString: 'assert.strictEqual(multiplesOf3and5(49), 543, ''<code>multiplesOf3and5(49)</code> should return 543.'');'
testString: 'assert.strictEqual(multiplesOf3and5(49), 543, "<code>multiplesOf3and5(49)</code> should return 543.");'
- text: <code>multiplesOf3and5(19564)</code> should return 89301183.
testString: 'assert.strictEqual(multiplesOf3and5(19564), 89301183, ''<code>multiplesOf3and5(19564)</code> should return 89301183.'');'
testString: 'assert.strictEqual(multiplesOf3and5(19564), 89301183, "<code>multiplesOf3and5(19564)</code> should return 89301183.");'
- text: Your function is not returning the correct result using our tests values.
testString: 'assert.strictEqual(multiplesOf3and5(8456), 16687353, ''Your function is not returning the correct result using our tests values.'');'
testString: 'assert.strictEqual(multiplesOf3and5(8456), 16687353, "Your function is not returning the correct result using our tests values.");'
```

View File

@ -21,13 +21,13 @@ Find the sum of all the primes below n.
```yml
tests:
- text: <code>primeSummation(17)</code> should return 41.
testString: 'assert.strictEqual(primeSummation(17), 41, ''<code>primeSummation(17)</code> should return 41.'');'
testString: 'assert.strictEqual(primeSummation(17), 41, "<code>primeSummation(17)</code> should return 41.");'
- text: <code>primeSummation(2001)</code> should return 277050.
testString: 'assert.strictEqual(primeSummation(2001), 277050, ''<code>primeSummation(2001)</code> should return 277050.'');'
testString: 'assert.strictEqual(primeSummation(2001), 277050, "<code>primeSummation(2001)</code> should return 277050.");'
- text: <code>primeSummation(140759)</code> should return 873608362.
testString: 'assert.strictEqual(primeSummation(140759), 873608362, ''<code>primeSummation(140759)</code> should return 873608362.'');'
testString: 'assert.strictEqual(primeSummation(140759), 873608362, "<code>primeSummation(140759)</code> should return 873608362.");'
- text: <code>primeSummation(2000000)</code> should return 142913828922.
testString: 'assert.strictEqual(primeSummation(2000000), 142913828922, ''<code>primeSummation(2000000)</code> should return 142913828922.'');'
testString: 'assert.strictEqual(primeSummation(2000000), 142913828922, "<code>primeSummation(2000000)</code> should return 142913828922.");'
```

View File

@ -22,7 +22,7 @@ By finding the first arrangement to contain over 1012 = 1,000,000,000,000 discs
```yml
tests:
- text: <code>euler100()</code> should return 756872327473.
testString: 'assert.strictEqual(euler100(), 756872327473, ''<code>euler100()</code> should return 756872327473.'');'
testString: 'assert.strictEqual(euler100(), 756872327473, "<code>euler100()</code> should return 756872327473.");'
```

View File

@ -40,7 +40,7 @@ Find the sum of FITs for the BOPs.
```yml
tests:
- text: <code>euler101()</code> should return 37076114526.
testString: 'assert.strictEqual(euler101(), 37076114526, ''<code>euler101()</code> should return 37076114526.'');'
testString: 'assert.strictEqual(euler101(), 37076114526, "<code>euler101()</code> should return 37076114526.");'
```

View File

@ -26,7 +26,7 @@ NOTE: The first two examples in the file represent the triangles in the example
```yml
tests:
- text: <code>euler102()</code> should return 228.
testString: 'assert.strictEqual(euler102(), 228, ''<code>euler102()</code> should return 228.'');'
testString: 'assert.strictEqual(euler102(), 228, "<code>euler102()</code> should return 228.");'
```

View File

@ -28,7 +28,7 @@ NOTE: This problem is related to Problem 105 and Problem 106.
```yml
tests:
- text: <code>euler103()</code> should return 20313839404245.
testString: 'assert.strictEqual(euler103(), 20313839404245, ''<code>euler103()</code> should return 20313839404245.'');'
testString: 'assert.strictEqual(euler103(), 20313839404245, "<code>euler103()</code> should return 20313839404245.");'
```

View File

@ -23,7 +23,7 @@ Given that Fk is the first Fibonacci number for which the first nine digits AND
```yml
tests:
- text: <code>euler104()</code> should return 329468.
testString: 'assert.strictEqual(euler104(), 329468, ''<code>euler104()</code> should return 329468.'');'
testString: 'assert.strictEqual(euler104(), 329468, "<code>euler104()</code> should return 329468.");'
```

View File

@ -25,7 +25,7 @@ NOTE: This problem is related to Problem 103 and Problem 106.
```yml
tests:
- text: <code>euler105()</code> should return 73702.
testString: 'assert.strictEqual(euler105(), 73702, ''<code>euler105()</code> should return 73702.'');'
testString: 'assert.strictEqual(euler105(), 73702, "<code>euler105()</code> should return 73702.");'
```

View File

@ -26,7 +26,7 @@ NOTE: This problem is related to Problem 103 and Problem 105.
```yml
tests:
- text: <code>euler106()</code> should return 21384.
testString: 'assert.strictEqual(euler106(), 21384, ''<code>euler106()</code> should return 21384.'');'
testString: 'assert.strictEqual(euler106(), 21384, "<code>euler106()</code> should return 21384.");'
```

View File

@ -35,7 +35,7 @@ Using network.txt (right click and 'Save Link/Target As...'), a 6K text file con
```yml
tests:
- text: <code>euler107()</code> should return 259679.
testString: 'assert.strictEqual(euler107(), 259679, ''<code>euler107()</code> should return 259679.'');'
testString: 'assert.strictEqual(euler107(), 259679, "<code>euler107()</code> should return 259679.");'
```

View File

@ -24,7 +24,7 @@ What is the least value of <var>n</var> for which the number of distinct solutio
```yml
tests:
- text: <code>diophantineOne()</code> should return 180180.
testString: 'assert.strictEqual(diophantineOne(), 180180, ''<code>diophantineOne()</code> should return 180180.'');'
testString: 'assert.strictEqual(diophantineOne(), 180180, "<code>diophantineOne()</code> should return 180180.");'
```

View File

@ -66,7 +66,7 @@ How many distinct ways can a player checkout with a score less than 100?
```yml
tests:
- text: <code>euler109()</code> should return 38182.
testString: 'assert.strictEqual(euler109(), 38182, ''<code>euler109()</code> should return 38182.'');'
testString: 'assert.strictEqual(euler109(), 38182, "<code>euler109()</code> should return 38182.");'
```

View File

@ -44,9 +44,9 @@ What is the greatest product of four adjacent numbers in the same direction (up,
```yml
tests:
- text: <code>largestGridProduct(grid)</code> should return 70600674.
testString: 'assert.strictEqual(largestGridProduct(grid), 70600674, ''<code>largestGridProduct(grid)</code> should return 70600674.'');'
testString: 'assert.strictEqual(largestGridProduct(grid), 70600674, "<code>largestGridProduct(grid)</code> should return 70600674.");'
- text: <code>largestGridProduct(testGrid)</code> should return 14169081.
testString: 'assert.strictEqual(largestGridProduct(testGrid), 14169081, ''<code>largestGridProduct(testGrid)</code> should return 14169081.'');'
testString: 'assert.strictEqual(largestGridProduct(testGrid), 14169081, "<code>largestGridProduct(testGrid)</code> should return 14169081.");'
```

View File

@ -23,7 +23,7 @@ What is the least value of <var>n</var> for which the number of distinct solutio
```yml
tests:
- text: <code>diophantineTwo</code> should return 9350130049860600.
testString: 'assert.strictEqual(diophantineTwo(), 9350130049860600, ''<code>diophantineTwo()</code> should return 9350130049860600.'');'
testString: 'assert.strictEqual(diophantineTwo(), 9350130049860600, "<code>diophantineTwo()</code> should return 9350130049860600.");'
```

View File

@ -72,7 +72,7 @@ Find the sum of all S(10, d).
```yml
tests:
- text: <code>euler111()</code> should return 612407567715.
testString: 'assert.strictEqual(euler111(), 612407567715, ''<code>euler111()</code> should return 612407567715.'');'
testString: 'assert.strictEqual(euler111(), 612407567715, "<code>euler111()</code> should return 612407567715.");'
```

View File

@ -25,7 +25,7 @@ Find the least number for which the proportion of bouncy numbers is exactly 99%.
```yml
tests:
- text: <code>euler112()</code> should return 1587000.
testString: 'assert.strictEqual(euler112(), 1587000, ''<code>euler112()</code> should return 1587000.'');'
testString: 'assert.strictEqual(euler112(), 1587000, "<code>euler112()</code> should return 1587000.");'
```

View File

@ -24,7 +24,7 @@ How many numbers below a googol (10100) are not bouncy?
```yml
tests:
- text: <code>euler113()</code> should return 51161058134250.
testString: 'assert.strictEqual(euler113(), 51161058134250, ''<code>euler113()</code> should return 51161058134250.'');'
testString: 'assert.strictEqual(euler113(), 51161058134250, "<code>euler113()</code> should return 51161058134250.");'
```

View File

@ -123,7 +123,7 @@ NOTE: Although the example above does not lend itself to the possibility, in gen
```yml
tests:
- text: <code>euler114()</code> should return 16475640049.
testString: 'assert.strictEqual(euler114(), 16475640049, ''<code>euler114()</code> should return 16475640049.'');'
testString: 'assert.strictEqual(euler114(), 16475640049, "<code>euler114()</code> should return 16475640049.");'
```

View File

@ -26,7 +26,7 @@ For m = 50, find the least value of n for which the fill-count function first ex
```yml
tests:
- text: <code>euler115()</code> should return 168.
testString: 'assert.strictEqual(euler115(), 168, ''<code>euler115()</code> should return 168.'');'
testString: 'assert.strictEqual(euler115(), 168, "<code>euler115()</code> should return 168.");'
```

View File

@ -93,7 +93,7 @@ NOTE: This is related to Problem 117.
```yml
tests:
- text: <code>euler116()</code> should return 20492570929.
testString: 'assert.strictEqual(euler116(), 20492570929, ''<code>euler116()</code> should return 20492570929.'');'
testString: 'assert.strictEqual(euler116(), 20492570929, "<code>euler116()</code> should return 20492570929.");'
```

View File

@ -101,7 +101,7 @@ NOTE: This is related to Problem 116.
```yml
tests:
- text: <code>euler117()</code> should return 100808458960497.
testString: 'assert.strictEqual(euler117(), 100808458960497, ''<code>euler117()</code> should return 100808458960497.'');'
testString: 'assert.strictEqual(euler117(), 100808458960497, "<code>euler117()</code> should return 100808458960497.");'
```

View File

@ -21,7 +21,7 @@ How many distinct sets containing each of the digits one through nine exactly on
```yml
tests:
- text: <code>euler118()</code> should return 44680.
testString: 'assert.strictEqual(euler118(), 44680, ''<code>euler118()</code> should return 44680.'');'
testString: 'assert.strictEqual(euler118(), 44680, "<code>euler118()</code> should return 44680.");'
```

View File

@ -23,7 +23,7 @@ Find a30.
```yml
tests:
- text: <code>euler119()</code> should return 248155780267521.
testString: 'assert.strictEqual(euler119(), 248155780267521, ''<code>euler119()</code> should return 248155780267521.'');'
testString: 'assert.strictEqual(euler119(), 248155780267521, "<code>euler119()</code> should return 248155780267521.");'
```

View File

@ -31,15 +31,15 @@ What is the value of the first triangle number to have over <code>n</code> divis
```yml
tests:
- text: <code>divisibleTriangleNumber(5)</code> should return 28.
testString: 'assert.strictEqual(divisibleTriangleNumber(5), 28, ''<code>divisibleTriangleNumber(5)</code> should return 28.'');'
testString: 'assert.strictEqual(divisibleTriangleNumber(5), 28, "<code>divisibleTriangleNumber(5)</code> should return 28.");'
- text: <code>divisibleTriangleNumber(23)</code> should return 630.
testString: 'assert.strictEqual(divisibleTriangleNumber(23), 630, ''<code>divisibleTriangleNumber(23)</code> should return 630.'');'
testString: 'assert.strictEqual(divisibleTriangleNumber(23), 630, "<code>divisibleTriangleNumber(23)</code> should return 630.");'
- text: <code>divisibleTriangleNumber(167)</code> should return 1385280.
testString: 'assert.strictEqual(divisibleTriangleNumber(167), 1385280, ''<code>divisibleTriangleNumber(167)</code> should return 1385280.'');'
testString: 'assert.strictEqual(divisibleTriangleNumber(167), 1385280, "<code>divisibleTriangleNumber(167)</code> should return 1385280.");'
- text: <code>divisibleTriangleNumber(374)</code> should return 17907120.
testString: 'assert.strictEqual(divisibleTriangleNumber(374), 17907120, ''<code>divisibleTriangleNumber(374)</code> should return 17907120.'');'
testString: 'assert.strictEqual(divisibleTriangleNumber(374), 17907120, "<code>divisibleTriangleNumber(374)</code> should return 17907120.");'
- text: <code>divisibleTriangleNumber(500)</code> should return 76576500.
testString: 'assert.strictEqual(divisibleTriangleNumber(500), 76576500, ''<code>divisibleTriangleNumber(500)</code> should return 76576500.'');'
testString: 'assert.strictEqual(divisibleTriangleNumber(500), 76576500, "<code>divisibleTriangleNumber(500)</code> should return 76576500.");'
```

View File

@ -22,7 +22,7 @@ For 3 ≤ a ≤ 1000, find ∑ rmax.
```yml
tests:
- text: <code>euler120()</code> should return 333082500.
testString: 'assert.strictEqual(euler120(), 333082500, ''<code>euler120()</code> should return 333082500.'');'
testString: 'assert.strictEqual(euler120(), 333082500, "<code>euler120()</code> should return 333082500.");'
```

View File

@ -23,7 +23,7 @@ Find the maximum prize fund that should be allocated to a single game in which f
```yml
tests:
- text: <code>euler121()</code> should return 2269.
testString: 'assert.strictEqual(euler121(), 2269, ''<code>euler121()</code> should return 2269.'');'
testString: 'assert.strictEqual(euler121(), 2269, "<code>euler121()</code> should return 2269.");'
```

View File

@ -27,7 +27,7 @@ For 1 ≤ k ≤ 200, find ∑ m(k).
```yml
tests:
- text: <code>euler122()</code> should return 1582.
testString: 'assert.strictEqual(euler122(), 1582, ''<code>euler122()</code> should return 1582.'');'
testString: 'assert.strictEqual(euler122(), 1582, "<code>euler122()</code> should return 1582.");'
```

View File

@ -23,7 +23,7 @@ Find the least value of n for which the remainder first exceeds 1010.
```yml
tests:
- text: <code>euler123()</code> should return 21035.
testString: 'assert.strictEqual(euler123(), 21035, ''<code>euler123()</code> should return 21035.'');'
testString: 'assert.strictEqual(euler123(), 21035, "<code>euler123()</code> should return 21035.");'
```

View File

@ -62,7 +62,7 @@ If rad(n) is sorted for 1 ≤ n ≤ 100000, find E(10000).
```yml
tests:
- text: <code>euler124()</code> should return 21417.
testString: 'assert.strictEqual(euler124(), 21417, ''<code>euler124()</code> should return 21417.'');'
testString: 'assert.strictEqual(euler124(), 21417, "<code>euler124()</code> should return 21417.");'
```

View File

@ -22,7 +22,7 @@ Find the sum of all the numbers less than 108 that are both palindromic and can
```yml
tests:
- text: <code>euler125()</code> should return 2906969179.
testString: 'assert.strictEqual(euler125(), 2906969179, ''<code>euler125()</code> should return 2906969179.'');'
testString: 'assert.strictEqual(euler125(), 2906969179, "<code>euler125()</code> should return 2906969179.");'
```

View File

@ -27,7 +27,7 @@ Find the least value of n for which C(n) = 1000.
```yml
tests:
- text: <code>euler126()</code> should return 18522.
testString: 'assert.strictEqual(euler126(), 18522, ''<code>euler126()</code> should return 18522.'');'
testString: 'assert.strictEqual(euler126(), 18522, "<code>euler126()</code> should return 18522.");'
```

View File

@ -32,7 +32,7 @@ Find ∑c for c < 120000.
```yml
tests:
- text: <code>euler127()</code> should return 18407904.
testString: 'assert.strictEqual(euler127(), 18407904, ''<code>euler127()</code> should return 18407904.'');'
testString: 'assert.strictEqual(euler127(), 18407904, "<code>euler127()</code> should return 18407904.");'
```

View File

@ -29,7 +29,7 @@ Find the 2000th tile in this sequence.
```yml
tests:
- text: <code>euler128()</code> should return 14516824220.
testString: 'assert.strictEqual(euler128(), 14516824220, ''<code>euler128()</code> should return 14516824220.'');'
testString: 'assert.strictEqual(euler128(), 14516824220, "<code>euler128()</code> should return 14516824220.");'
```

View File

@ -23,7 +23,7 @@ Find the least value of n for which A(n) first exceeds one-million.
```yml
tests:
- text: <code>euler129()</code> should return 1000023.
testString: 'assert.strictEqual(euler129(), 1000023, ''<code>euler129()</code> should return 1000023.'');'
testString: 'assert.strictEqual(euler129(), 1000023, "<code>euler129()</code> should return 1000023.");'
```

View File

@ -121,9 +121,9 @@ Work out the first ten digits of the sum of the following one-hundred 50-digit n
```yml
tests:
- text: <code>largeSum(testNums)</code> should return 8348422521.
testString: 'assert.strictEqual(largeSum(testNums), 8348422521, ''<code>largeSum(testNums)</code> should return 8348422521.'');'
testString: 'assert.strictEqual(largeSum(testNums), 8348422521, "<code>largeSum(testNums)</code> should return 8348422521.");'
- text: <code>largeSum(fiftyDigitNums)</code> should return 5537376230.
testString: 'assert.strictEqual(largeSum(fiftyDigitNums), 5537376230, ''<code>largeSum(fiftyDigitNums)</code> should return 5537376230.'');'
testString: 'assert.strictEqual(largeSum(fiftyDigitNums), 5537376230, "<code>largeSum(fiftyDigitNums)</code> should return 5537376230.");'
```

View File

@ -24,7 +24,7 @@ Find the sum of the first twenty-five composite values of n for whichGCD(n, 10)
```yml
tests:
- text: <code>euler130()</code> should return 149253.
testString: 'assert.strictEqual(euler130(), 149253, ''<code>euler130()</code> should return 149253.'');'
testString: 'assert.strictEqual(euler130(), 149253, "<code>euler130()</code> should return 149253.");'
```

View File

@ -23,7 +23,7 @@ How many primes below one million have this remarkable property?
```yml
tests:
- text: <code>euler131()</code> should return 173.
testString: 'assert.strictEqual(euler131(), 173, ''<code>euler131()</code> should return 173.'');'
testString: 'assert.strictEqual(euler131(), 173, "<code>euler131()</code> should return 173.");'
```

View File

@ -22,7 +22,7 @@ Find the sum of the first forty prime factors of R(109).
```yml
tests:
- text: <code>euler132()</code> should return 843296.
testString: 'assert.strictEqual(euler132(), 843296, ''<code>euler132()</code> should return 843296.'');'
testString: 'assert.strictEqual(euler132(), 843296, "<code>euler132()</code> should return 843296.");'
```

View File

@ -23,7 +23,7 @@ Find the sum of all the primes below one-hundred thousand that will never be a f
```yml
tests:
- text: <code>euler133()</code> should return 453647705.
testString: 'assert.strictEqual(euler133(), 453647705, ''<code>euler133()</code> should return 453647705.'');'
testString: 'assert.strictEqual(euler133(), 453647705, "<code>euler133()</code> should return 453647705.");'
```

View File

@ -22,7 +22,7 @@ Find ∑ S for every pair of consecutive primes with 5 ≤ p1 ≤ 1000000.
```yml
tests:
- text: <code>euler134()</code> should return 18613426663617120.
testString: 'assert.strictEqual(euler134(), 18613426663617120, ''<code>euler134()</code> should return 18613426663617120.'');'
testString: 'assert.strictEqual(euler134(), 18613426663617120, "<code>euler134()</code> should return 18613426663617120.");'
```

View File

@ -23,7 +23,7 @@ How many values of n less than one million have exactly ten distinct solutions?
```yml
tests:
- text: <code>euler135()</code> should return 4989.
testString: 'assert.strictEqual(euler135(), 4989, ''<code>euler135()</code> should return 4989.'');'
testString: 'assert.strictEqual(euler135(), 4989, "<code>euler135()</code> should return 4989.");'
```

View File

@ -23,7 +23,7 @@ How many values of n less than fifty million have exactly one solution?
```yml
tests:
- text: <code>euler136()</code> should return 2544559.
testString: 'assert.strictEqual(euler136(), 2544559, ''<code>euler136()</code> should return 2544559.'');'
testString: 'assert.strictEqual(euler136(), 2544559, "<code>euler136()</code> should return 2544559.");'
```

View File

@ -41,7 +41,7 @@ Find the 15th golden nugget.
```yml
tests:
- text: <code>euler137()</code> should return 1120149658760.
testString: 'assert.strictEqual(euler137(), 1120149658760, ''<code>euler137()</code> should return 1120149658760.'');'
testString: 'assert.strictEqual(euler137(), 1120149658760, "<code>euler137()</code> should return 1120149658760.");'
```

View File

@ -25,7 +25,7 @@ Find ∑ L for the twelve smallest isosceles triangles for which h = b ± 1 and
```yml
tests:
- text: <code>euler138()</code> should return 1118049290473932.
testString: 'assert.strictEqual(euler138(), 1118049290473932, ''<code>euler138()</code> should return 1118049290473932.'');'
testString: 'assert.strictEqual(euler138(), 1118049290473932, "<code>euler138()</code> should return 1118049290473932.");'
```

Some files were not shown because too many files have changed in this diff Show More