Skip to content

Latest commit

 

History

History
190 lines (127 loc) · 3.13 KB

arrays.md

File metadata and controls

190 lines (127 loc) · 3.13 KB

Arrays

{id: array}

Arrays intro

{id: array-intro}

Array elements - indexing

{id: array-elements}

Array iterate over (each, each_with_index)

{id: array-iterate} {i: each} {i: each_with_index}

Array push, append, <<

{id: array-push} {i: push} {i: append} {i: <<}

Empty array

{id: array-empty}

  • Empty array must come with a type definition

Count digits

{id: array-count-digits}

Operations on arrays

{id: array-operations}

  • add +
  • repeat *

Add arrays

{id: add-arrays}

Repeat arrays

{id: repeat-arrays}

Select (filter, grep)

{id: select} {i: select} {i: select!} {i: filter} {i: grep}

Reject (negative filter, grep)

{id: reject} {i: reject} {i: reject!} {i: filter} {i: grep}

  • the reject! with the exclamation mark will modify the array
  • the reject without the exclamation mark will only return the filtered array

Transform with map

{id: transform-with-map} {i: map} {i: map!}

Sample from array

{id: array-sample} {i: sample}

  • Using Random behind the scenes.

Shuffle array

{id: array-shuffle} {i: shuffle}

  • Using Random behind the scenes.

join

{id: array-join}

Remove nil elements

{id: remove-nil-elements} {i: compact}

Create Array with nil

{id: array-with-nil} {i: 0_i64}

Does array include a value

{id: array-includes} {i: includes?}

Delete element from array by value

{id: array-delete} {i: delete}

Delete element from array by location

{id: array-delete-at} {i: delete_at}

Insert element into array at location

{id: array-insert} {i: insert}

Arrays shift - remove first element

{id: array-shift} {i: shift}

Arrays uniq elements

{id: array-uniq} {i: uniq} {i: uniq!}

First element of the array

{id: array-first} {i: first} {i: first?}

Permutations

{id: array-permutations} {i: permutations}