Alex
12/09/2021, 5:59 PMval x:DoubleArray = doubleArrayOf(0.0, 0.19, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25)
the values are records every 1.5s distance travelled, in this case 0.0 is the starting point 0.19 is when the distance covered is recorded at 1.5 seconds mark after another 1.5 seconds the distance of 0.5 is recorded and so on.
2. I need to find the difference in distances as following 0.0-0.19, 0.19-0.5, 0.5-0.75, 0.75-1.0, 1.0-1.25, 1.25-1.50, 1.5-1.75, 1.75-2.0, 2.0-2.25
, i know how to use map(to double values or multiple then) but i don't know how to subtract from a preceded value with a previous value in an Array
3. you can refer to the full question if my explanation is not clear, i just need to find the difference in distances before i can proceed to do the next step, hope someone can help me on this 😅Joffrey
12/09/2021, 6:11 PMzipWithNext
:)Alex
12/09/2021, 6:22 PMzipWithNext
val differenceInDistance=x.toList().zipWithNext{a,b->b-a}
when i add toDoubleArray though, nothing get printed out, without it values get printed out but as a listJoffrey
12/09/2021, 6:28 PMprintln(myArray)
which doesn't print the elements of the array but instead prints the array object reference (something like [D@3343c8b3
). This is unfortunately how the JVM does things because arrays use the default toString()
method. If you want to use an array anyway and print it, you can use println(Arrays.toString(myArray))
Paul Griffith
12/09/2021, 6:40 PMcontentToString()
extension function for arrays to print the contentsJoffrey
12/09/2021, 6:47 PMAlex
12/10/2021, 3:17 PMJoffrey
12/10/2021, 4:04 PMAlex
12/11/2021, 7:08 PMAlex
12/12/2021, 3:05 PMPaul Griffith
12/14/2021, 3:10 PMzipWithNext
and lots of the other array extensions return Lists instead of arrays)