typestar

Partir y unir en Smalltalk

substrings parte por espacios; los streams vuelven a unir.

"substrings splits on whitespace; joins go through streams."
| note words |
note := 'wash rollers then oil the platen'.
words := note substrings.

Transcript show: words size printString, ' words'; cr.
Transcript show: words first, ' ... ', words last; cr.

"Filter and rejoin the long words."
Transcript show: (String streamContents: [:s |
    (words select: [:w | w size > 4])
        do: [:w | s nextPutAll: w]
        separatedBy: [s nextPutAll: ', ']]); cr.

Transcript show: ('folio-recto-verso' substrings: '-') printString; cr.

Cómo funciona

  1. substrings rompe una oración en palabras.
  2. Un select alimenta do:separatedBy: dentro de streamContents:.
  3. substrings: '-' parte por separadores elegidos.

El intento, en números

Líneas
15
Caracteres a escribir
515
Tokens
89
Ritmo de tres estrellas
55 tpm

Al ritmo de tres estrellas de 55 tokens por minuto, este intento toma unos 97 segundos.

Escribe este fragmento

Paso 3 de 3 en Strings; paso 20 de 31 en Fundamentos del lenguaje.

← Anterior Siguiente →