我Math在Kotlin中添加了一个函数,但是我无法使用它,我之前使用它MutableList并且它有效但我无法用Math类来完成它.
fun Math.divideWithSubtract(num1: Int, num2: Int) =
Math.exp(Math.log(num1.toDouble())) - Math.exp(Math.log(num2.toDouble()))
Run Code Online (Sandbox Code Playgroud) var listOfNums = listOf(1,9,8,25,5,44,7,95,9,10)
var mapOfNums = listOfNums.map { it to it+1 }.toMap()
println(mapOfNums)
Run Code Online (Sandbox Code Playgroud)
结果
{1=2, 9=10, 8=9, 25=26, 5=6, 44=45, 7=8, 95=96, 10=11}
Run Code Online (Sandbox Code Playgroud)
虽然我需要这个结果,但是当我需要将当前元素映射到下一个元素时,它会将下一个元素的内容添加到当前元素
我的目标结果
{1=9, 8=25, 5=44, 7=59, 9=10}
Run Code Online (Sandbox Code Playgroud)