Skip to content

Instantly share code, notes, and snippets.

@radex
Created March 23, 2013 08:34
Show Gist options
  • Save radex/5227018 to your computer and use it in GitHub Desktop.
Save radex/5227018 to your computer and use it in GitHub Desktop.
Playing around with CoffeeScript's comprehensions. Not practical to nest them like that, but definitely fun that it's even possible!
text = """Messiah (HWV 56) is an English-language oratorio composed in 1741 by George Frideric Handel, with a scriptural text compiled by Charles Jennens from the King James Bible and the Book of Common Prayer. Messiah was first performed in Dublin in 1742, and received its London premiere the following year. After an initially modest public reception, the oratorio gained in popularity, becoming one of the most frequently performed choral works in Western music. Although its structure resembles that of opera, it is not in dramatic form, but a reflection on Jesus Christ as Messiah. Handel begins Part I with prophecies by Isaiah and others, and moves to the annunciation to the shepherds, the only "scene" taken from the Gospels. In Part II he concentrates on the Passion and ends with the Hallelujah Chorus. In Part III he covers the resurrection of the dead and Christ's glorification in heaven. Handel wrote Messiah for modest vocal and instrumental forces; after his death, the work was adapted for performance with much larger orchestras and choirs. Its orchestration was revised and amplified by (among others) Mozart. Since the late 20th century, the trend has been towards authenticity. (Full article...)"""
alphabet = 'abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ '
// finds words that are 5-7 letter long and start with a capital letter
console.log (word for word in (text[i] for i in [0...text.length] when text[i] in alphabet).join('').split(' ') when word not in [' ', ''] and word.length in [5..7] and word.charCodeAt(0) in [65..90])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment