官术网_书友最值得收藏!

How to do it...

  1. Create a new file, Extensions.kt, to store the extension function definition. 
  2. Implement the swap() function inside:
fun <T> Array<T>.swap(a: T, b: T) {
val positionA = indexOf(a)
val positionB = indexOf(b)

if (positionA < 0 || positionB < 0) {
throw IllegalArgumentException("Given param doesn't belong
to the array"
)
}

val tmp = this[positionA]
this[positionA] = this[positionB]
this[positionB] = tmp
}
主站蜘蛛池模板: 中牟县| 岐山县| 永靖县| 漳浦县| 兴山县| 石狮市| 清流县| 开封市| 乾安县| 宁安市| 芦山县| 祁门县| 陆河县| 江门市| 宜川县| 滦南县| 临潭县| 竹溪县| 汝阳县| 元氏县| 鸡东县| 定西市| 崇文区| 通渭县| 惠来县| 长治县| 镇平县| 玉山县| 陇南市| 清河县| 新丰县| 忻城县| 南郑县| 和田县| 五家渠市| 祁连县| 新营市| 南阳市| 苍山县| 长葛市| 正阳县|