about | help | code help+videos | done | prefs |
Write a method swapPairs that accepts an array of strings as a parameter, returns a new array of strings which swaps the order of values in a pairwise fashion. Your method should switch the order of the first two String values, then switch the order of the next two, switch the order of the next two, and so on... For example, if the array has these strings: {four score and seven years ago} - the new array would be [score four seven and ago years] If the parameter array is empty - return an empty array. In an odd length string array the last element would not be moved. swapPairs([""]) → [""] swapPairs(["four", "score", "and", "seven", "years", "ago"]) → ["score", "four", "seven", "and", "ago", "years"] swapPairs(["to", "be", "or", "not", "to", "be", "hamlet"]) → ["be", "to", "not", "or", "be", "to", "hamlet"] ...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: 140
Copyright Nick Parlante 2017 - privacy