Skip to content

Commit b9bd319

Browse files
committed
update
1 parent 34c8074 commit b9bd319

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Hello, world](hello-world.md)
99
- [Objects, Methods & Integers](objects-methods-and-integers.md)
1010
- [Loops, Blocks & Strings](loops-blocks-and-strings.md)
11-
- [Arrays and Floats](arrays-and-floats.md)
11+
- [Arrays & Floats](arrays-and-floats.md)
1212

1313
## Meta
1414

arrays-and-floats.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,27 @@ git add average_test.rb average.rb
417417
git commit -m 'feat: add average function'
418418
```
419419

420+
## Other useful Array methods
421+
422+
As you may have noticed, Ruby’s standard library comes with a lot of useful solutions (for example, Array#sum).
423+
424+
Other quite handy Array methods provided by default are:
425+
426+
- `#each_with_index` – use this when you want to iterate over each element and need the index.
427+
- `#sort` – returns a new array with the elements of the original array, but sorted.
428+
- `#sort_by` – similar to `#sort`, but allows you to specify the sorting criterion.
429+
- `#min`, `#max` – returns the minimum/maximum valued element in the array.
430+
- `#minmax` – returns a new 2-element array containing the minimum and maximum values.
431+
432+
This is a short list of the Array’s methods. Be sure to spend some time reading [the Array class documentation](https://ruby-doc.org/current/Array.html); it’s a worthwhile investment of your time.
420433

421434
## Key Concepts
422435

423436
### Ruby
424437

425-
- Array#sum: get the sum the numbers in an array
426-
- Array#length (aliased as Array#size): get the amount of elements in an array
438+
- Array#sum: get the sum the numbers in an array.
439+
- Array#length (aliased as Array#size): get the amount of elements in an array.
440+
- The default Ruby library has many other useful methods for handling Arrays.
427441
- Division of integers always result in a truncated integer.
428442
- Change the divisor to a float to get the result in a float.
429443
- Floating point numbers are not always accurate.

0 commit comments

Comments
 (0)