- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 66字
- 2021-07-23 19:05:54
How to do it...
- Create a new file, Extensions.kt, to store the extension function definition.
- 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
}
推薦閱讀
- Node.js+Webpack開發(fā)實戰(zhàn)
- PHP網(wǎng)絡(luò)編程學(xué)習(xí)筆記
- Silverlight魔幻銀燈
- Python數(shù)據(jù)可視化之Matplotlib與Pyecharts實戰(zhàn)
- Python數(shù)據(jù)分析從0到1
- Python面向?qū)ο缶幊蹋簶?gòu)建游戲和GUI
- Web Development with MongoDB and Node(Third Edition)
- 精通Python自動化編程
- Java程序設(shè)計入門
- Java編程的邏輯
- PHP從入門到精通(第4版)(軟件開發(fā)視頻大講堂)
- 玩轉(zhuǎn).NET Micro Framework移植:基于STM32F10x處理器
- JavaScript悟道
- Scrapy網(wǎng)絡(luò)爬蟲實戰(zhàn)
- Python程序設(shè)計教程