## HI guys! I’m working on the direction reduction exercise and I thought I’ve finally figured it out but am having an issue with the “results.dropLast(1)” . For some reason it’s not dropping “SOUTH” as it should. (ive printed “Results” before and after to see). Can someone please explain the issue?

my code:

fun main() { val arr = arrayOf("NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST") var results = arrayOf&lt;String&gt;("placeholder") var counter = 0 fun checkSkip(): Boolean { if (counter == 0) { return false } else { return true } } for (i in 0..arr.size -2) { if (arr[i] == "NORTH" &amp;&amp; arr[i + 1] == "SOUTH" || arr[i] == "SOUTH" &amp;&amp; arr[i + 1] == "NORTH" || arr[i] == "WEST" &amp;&amp; arr[i + 1] == "EAST" || arr[i] == "EAST" &amp;&amp; arr[i + 1] == "WEST") { counter += 1 } else if (arr[i] == "NORTH" &amp;&amp; arr[i - 1] == "SOUTH" || arr[i] == "SOUTH" &amp;&amp; arr[i - 1] == "NORTH" || arr[i] == "WEST" &amp;&amp; arr[i - 1] == "EAST" || arr[i] == "EAST" &amp;&amp; arr[i - 1] == "WEST" &amp;&amp; checkSkip() == true) { counter -= 1 } else { if (arr[i] == "NORTH" &amp;&amp; results[results.size - 1] == "SOUTH" || arr[i] == "SOUTH" &amp;&amp; results[results.size - 1] == "NORTH" || arr[i] == "WEST" &amp;&amp; results[results.size - 1] == "EAST" || arr[i] == "EAST" &amp;&amp; results[results.size - 1] == "WEST") { println(results.joinToString()) results.dropLast(1) println(results.joinToString()) counter -= 1 } else { results += arr[i] counter += 1 } } } println(results.drop(1).joinToString()) if (checkSkip() == false) results += arr[arr.size - 1] println(results.drop(1).joinToString()) }

submitted by /u/SkeeterIsBlue