Calculating squares and cubes

Here is an example of using the |map modifier with arrow functions to transform array values.

  • 
    start:
      set:
        numbers@csv: {{range(1, 10)|join(',')}}
      return:
        squares@json: {{numbers|map((n) => n ** 2)|json_encode}}
        cubes@json: {{numbers|map((n) => n ** 3)|json_encode}}
    
    
  • 
    __return:
      squares:
      - 1
      - 4
      - 9
      - 16
      - 25
      - 36
      - 49
      - 64
      - 81
      - 100
      cubes:
      - 1
      - 8
      - 27
      - 64
      - 125
      - 216
      - 343
      - 512
      - 729
      - 1000