Groovy web console

subscribe to the feed Subscribe
to this

Jeet's challange

Published 3 months ago by Anonymous
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
// Omit the part reading from a file, assume the list already contains the lines
def lines = [
 'This is first line of the document',
 'The second one containing [Unreleased] token to be removed',
 ' of the lines...'

println "collect() method produces a `List` of transformed objects (it's an equivalent of from Javascript)."
println 'Below we can see how the `List` object looks like after serializing to `String`:'
println ''
println lines.collect {
    it.replace('[Unreleased]', '').trim()
println ''
println "We need to convert the lines `List` object into a String where each list item will be a seaparate line"
println "We need to call a join() method, see"
println 'Below we can see the expected output after joining all the list items by using System.lineSeparator():'
println lines.collect {
    it.replace('[Unreleased]', '').trim()