Home > Blockchain >  How to write the filter condition in ruby
How to write the filter condition in ruby

Time:03-30

I have some code logic which is written in javascript. I am new to ruby and I would like to write the same logic in Ruby. Here is the logic

var accountsToBlock = allExceedersArray.filter(accountId => !blockedExceedersArray.includes(accountId));

CodePudding user response:

Try something like this

accounts_to_block = all_exceeders_array.select do |account_id| 
  !blocked_exceeders_array.include?(account_id) 
end

CodePudding user response:

ruby also has a filter method, but I would look at the ruby reject method, as it's more readable to say

all_exceeders.reject { |account_id| blocked_exceeders.include?(account_id) }

than

all_exceeders.filter { |account_id| !blocked_exceeders.include?(account_id) }
  • Related