Created
March 1, 2021 14:08
-
-
Save bogoreh/09e2a97103ccca0019330dfc461a6ceb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //swapping the values that are passed to this function | |
| var swap = function(array, firstIndex, secondIndex) { | |
| var temp = array[firstIndex]; | |
| array[firstIndex] = array[secondIndex]; | |
| array[secondIndex] = temp; | |
| }; | |
| //declaring testArray and assigning it numbers | |
| var testArray = [7, 9, 4]; | |
| //first test | |
| swap(testArray, 0, 1); | |
| println(testArray); | |
| Program.assertEqual(testArray, [9, 7, 4]); | |
| //second test | |
| swap(testArray, 0, 2); | |
| println(testArray); | |
| Program.assertEqual(testArray, [4, 7, 9]); | |
| //third test | |
| swap(testArray, 1, 2); | |
| println(testArray); | |
| Program.assertEqual(testArray, [4, 9, 7]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment