about | help | code help+videos | done | prefs |
This function swaps the FIRST two elements of a given array of int values, and returns the modified array. Note that this function returns a whole array, not just an int. You could just mutate the elements of and return nums, if you want. Other problems might require you to make and alter a copy of an array, but changing the insides of the parameter object is authorized, here. Precondition: nums will contain at least two elements. SWAPPING ELEMENTS When swapping two elements (call them element Jamal and element Rosa) of an array, copy the value of one of them (let's say Jamal) to a temporary variable. Then, overwrite Jamal with the value of element Rosa, and finally overwrite Rosa with the value of Jamal (stored in the temp variable).apcsaArraysSwapFirstElements([3, 4]) → [4, 3] apcsaArraysSwapFirstElements([5, 8]) → [8, 5] apcsaArraysSwapFirstElements([9, 2, 4, 6]) → [2, 9, 4, 6] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 210
Copyright Nick Parlante 2017 - privacy