Created
May 9, 2017 16:44
-
-
Save think2011/b44185d89ea914f3436974e213fe0046 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
/** | |
* 交换数组的位置 | |
* @param arr | |
* @param i {Number} 旧的位置 | |
* @param j {Number} 新的位置 | |
* @returns {*} | |
*/ | |
function swap(arr, i, j) { | |
let tmp = arr[i] | |
arr[i] = arr[j] | |
arr[j] = tmp | |
return arr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment