# Mode

```ruby
func mode(array) {
    var c = Hash()
    array.each{|i| c{i} := 0 ++}
    var max = c.values.max
    c.keys.grep{|i| c{i} == max}
}
```

*Calling the function*

```ruby
say mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]).join(' ')
say mode([1, 1, 2, 4, 4]).join(' ')
```

#### Output:

```
6
1 4
```

If you just want one mode (instead of all of them), here's a one-liner for that:

```ruby
func one_mode(arr) {
    arr.max_by{|i| arr.count(i)}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/a/averages/mode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
