J@ArangoDB

{ "subject" : "ArangoDB", "tags": [ "multi-model", "nosql", "database" ] }

99 Bottles of Beer

99 bottles of beer in AQL:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
FOR quant IN 99..0 
  LET toPrint = (
    quant > 1 ? 
      CONCAT(TO_STRING(quant), " bottles of beer on the wall, ", TO_STRING(quant), " bottles of beer.") : 
      (quant == 1 ? 
        "1 bottle of beer on the wall, 1 bottle of beer." :
        "No more bottles of beer on the wall, no more bottles of beer."
      )
  )
 
  LET suffix = (
    quant > 2 ? 
      CONCAT(TO_STRING(quant - 1), " bottles of beer on the wall.") :
      (quant == 2 ? 
        "1 bottle of beer on the wall." :
        "no more bottles of beer on the wall."
      )
  )
 
  LET result = (
    quant > 0 ? 
      CONCAT(toPrint, "\nTake one down, pass it around, ", suffix) : 
      CONCAT(toPrint, "\nGo to the store and buy some more, 99 bottles of beer on the wall.")
  )

  RETURN result