> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/f/forward_difference.md).

# Forward difference

```ruby
func dif(arr) {
    gather {
        for i (0 ..^ arr.end) {
            take(arr[i+1] - arr[i])
        }
    }
}
 
func difn(n, arr) {
    { arr = dif(arr) } * n
    arr
}
 
say dif([1, 23, 45, 678])       # => [22, 22, 633]
say difn(2, [1, 23, 45, 678])   # => [0, 611]
```
