This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # editorconfig.org | |
| root = true | |
| [*] | |
| indent_style = space | |
| indent_size = 2 | |
| tab_width = 2 | |
| end_of_line = lf | |
| charset = utf-8 | |
| max_line_length = 80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark/ips' | |
| def find_one_using_group_by_select(array) | |
| array.group_by{ |e| e }.detect { |k, v| k if v.size > 1 }&.first | |
| end | |
| def find_one_using_chunk_select(array) | |
| array.sort.chunk{ |e| e }.detect { |e, chunk| chunk.size > 1 }&.first | |
| end |
When learning about sorting algorithms, I wanted to implement them to help me understand them better. This algorithm was originally invented by John von Neumann in 1948.
The Ruby script attached explains in real code what is going on. Play about with it.
Step by step:
- Pass through an array of unsorted numbers (i.e.
[4, 3, 2, 10])
- Website: https://stimulusjs.org/
- GitHub repo: https://github.com/stimulusjs/stimulus
- Handbook: https://stimulusjs.org/handbook/introduction
- Discourse: https://discourse.stimulusjs.org/
initialize: once, when the controller is first instantiatedconnect: anytime the controller is connected to the DOM
OlderNewer