Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Concept & Exercise]: Iteration #627

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

meatball133
Copy link
Member

No description provided.

@meatball133 meatball133 marked this pull request as ready for review May 18, 2024 15:29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this might be introducing too much. It's not just iteration, it's also introducing:

  • present?, empty?, any?, all?, none?, one?
  • count
  • sort_by

I would have expected this exercise to be about each and times and possibly map and reduce.

Both the `Array` and `Range` classes in Crystal include the [`Enumerable`][enumerable] module, which provides a number of methods for iterating over the elements.
Meanwhile, the `String` class has its own set of methods for iterating over the characters.

Crystal also doesnt have any any for statement like other languages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Crystal also doesnt have any any for statement like other languages.
Crystal also doesn't have any for statement like other languages.


The most common way to iterate over a collection is to use the [`each`][each] method, which yields each element in the collection to a block.
This can be done easily with a `Range`.
Say you would want to loop between 1 and 3, you can use the `each` method to iterate over the range.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Say you would want to loop between 1 and 3, you can use the `each` method to iterate over the range.
Say you want to loop between 1 and 3, you can use the `each` method to iterate over the range.

# 3
```

Even simplier if you just want to iterate n numbers of times you can use the [`times`][times] method, which exists on the `Int` class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Even simplier if you just want to iterate n numbers of times you can use the [`times`][times] method, which exists on the `Int` class.
Even simpler, if you just want to iterate a number of times you can use the [`times`][times] method, which exists on the `Int` class.


## Iterating over a `String`

A `String` is a sequence of characters, and doesnt belong to the `Enumerable` module, which means it has its own set of methods for iterating over the characters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `String` is a sequence of characters, and doesnt belong to the `Enumerable` module, which means it has its own set of methods for iterating over the characters.
A `String` is a sequence of characters and doesn't belong to the `Enumerable` module, which means it has its own set of methods for iterating over the characters.

# o
```

Another way of iterating over a `String` is to use the [`each_line`][each_line] method, this method is mostly used when reading a file line by line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Another way of iterating over a `String` is to use the [`each_line`][each_line] method, this method is mostly used when reading a file line by line.
Another way of iterating over a `String` is to use the [`each_line`][each_line] method.
This method is mostly used when reading a file line by line.

SpellboundSteel.calculate_power_level(deck).should eq(35)
end

it "should return 65 if the deck has a Rogue and Ice Storm " do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "should return 65 if the deck has a Rogue and Ice Storm " do
it "should return 65 if the deck has a Rogue and an Ice Storm " do

SpellboundSteel.decode_characters("").should eq("")
end

it "should return warrior if the inut is wbalrrrlimoqr" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "should return warrior if the inut is wbalrrrlimoqr" do
it "should return warrior if the input is wbalrrrlimoqr" do

SpellboundSteel.decode_characters("wbalrrrlimoqr").should eq("warrior")
end

it "should return mage if the inut is mlabgle" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "should return mage if the inut is mlabgle" do
it "should return mage if the input is mlabgle" do

SpellboundSteel.decode_characters("mlabgle").should eq("mage")
end

it "should return rogue if the inut is rloguqgle" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "should return rogue if the inut is rloguqgle" do
it "should return rogue if the input is rloggquge" do

Comment on lines +14 to +17
def self.sort_cards_by_power_level(characters)
raise "Please implement the SpellboundSteel.sort_cards_by_power_level method"
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def self.sort_cards_by_power_level(characters)
raise "Please implement the SpellboundSteel.sort_cards_by_power_level method"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants