Enumerators: Ruby Docs Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what value does this return??

A

arr = [“ant”, “bear”, “wolverine”]
arr.all? { |x| x != “dragon”}
——
returns true #==> no value is “dragon”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Given a collection, how do you enumerate over each item and return the values based on if they meet the block’s test or not?

A
arr= ["dragon", "alpha", "donkey", "doofus", "ranger", "dumbledore", "domain"]
arr.chunk { |n| n[0] == "d"}.each { |dLetter, ary| p [dLetter, ary]}
--------- RETURNS
[true, ["dragon"]]
[false, ["alpha"]]
[true, ["donkey", "doofus"]]
[false, ["ranger"]]
[true, ["dumbledore", "domain"]]
=> nil
How well did you know this?
1
Not at all
2
3
4
5
Perfectly