Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Created March 1, 2021 14:08
Show Gist options
  • Select an option

  • Save bogoreh/09e2a97103ccca0019330dfc461a6ceb to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/09e2a97103ccca0019330dfc461a6ceb to your computer and use it in GitHub Desktop.
//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