Jump to content

Split a character string based on change of character: Difference between revisions

(Undo revision 263340 by Gerard Schildberger (talk))
Line 1,157:
// See https://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character#Scala
 
def runningLengthrunLengthSplit(s: String): String = /// Add a guard letter
(s + 'X').sliding(2).map(pair => pair.head + (if (pair.head != pair.last) ", " else "")).mkString("")
 
println(runningLengthrunLengthSplit("""gHHH5YY++///\"""))</lang>
{{Out}}See it in running in your browser by [https://scalafiddle.io/sf/c4dp8GT/2 ScalaFiddle (JavaScript)]
or by [https://scastie.scala-lang.org/mDoBS77YSG2Z7w5xdAPzcw Scastie (JVM)].
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.