July 2018
Intermediate to advanced
336 pages
9h 23m
English
Infix notations can be used to define functions that can be used, such as 1 + 2, 2 - 3, true && false, a == b statements where there is an operator and two operands. The following function with the infix notation can be used to ZIP (interweave) words together in a way that the letters of each String are joined together to create a new String that has overlapping letters:
infix fun String.zip(s1 : String) : String { var result : String = ""; var zipLength : Int = Math.min(s1.length, this.length); for(i in 0..zipLength-1) { result += this[i]; result += s1[i]; } return result;}
The preceding function can be called as follows:
println("acegikmoqsuwy" zip "bdfhjlnprtvxz");
This will produce the following string as ...
Read now
Unlock full access