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

[Relaunch] Suggested changes in code snippets #677

Open
beta-ziliani opened this issue Mar 5, 2024 · 1 comment
Open

[Relaunch] Suggested changes in code snippets #677

beta-ziliani opened this issue Mar 5, 2024 · 1 comment
Labels

Comments

@beta-ziliani
Copy link
Member

Syntax:

  1. It was wrong (crashed with empty string)
  2. It was suggesting to press play, but no play button so far

Suggestion:

class String
  def longest_repetition?
    max = chars
            .chunk(&.itself)
            .map(&.last)
            .max_by?(&.size)

    {max[0], max.size} if max
  end
end

puts "aaabb".longest_repetition? # => {'a', 3}

Concurrency

Add some forced sleep to enforce the notion of concurrent events

Suggestion:

channel = Channel(Int32).new

3.times do |i|
  spawn do
    3.times do |j|
      sleep rand(100).milliseconds
      channel.send 10 * (i + 1) + j
    end
  end
end

9.times do
  puts channel.receive
end
@straight-shoota
Copy link
Member

@beta-ziliani Is there anything left to do here?

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

No branches or pull requests

2 participants