Rails 6.1.0 adds compact_blank and compact_blank! to ActiveSupport which makes it easier for removing blank values from an Enumerable / ActionController::Parameters.

Before Rails 6.1

Removing blank values from an array:

Removing blank values from a hash:

Rails 6.1

Removing blank values from an array:

You can also use compact_blank! which mutates its receiver:

Removing blank values from a hash:

Using compact_blank!:

--

--

Just 13 lines of code, I promise

Photo by Austin Distel on Unsplash

First, we need to define the stocks we wanna watch:

Then let's use Python's ffn library to get the closing prices of the last three trading sessions (three because we might be on a weekend):

Once we have the prices, let's calculate the percentual change over the days, remove any n/a values and get the last price diff using iloc[-1:]:

We also need to transpose the data frame and reset the index before advancing to the final step:

Here we get the top 5 best and worst performing stocks over the last trading session.

Putting all together now:

--

--

For some reason you are simulating links with JavaScript like:

But you want to open the link in another tab as you do when clicking on the link with Command pressed.

There you go:

metaKey is Command key on macOS and Windows key on Windows.

You might want to check its support across browsers.

Bonus

There is also another property ctrlKey with the same behaviour but for Ctrl key on Windows and Control on macOS.

--

--