We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deffunc_any(hash)# Check and return true if any key object within the hash is of the type Integer# If not found, return false.hash.keys.any?{|key|key.is_a?(Integer)}enddeffunc_all(hash)# Check and return true if all the values within the hash are Integers and are < 10# If not all values satisfy this, return false.hash.all?{|key,value|value.is_a?(Integer)&&value<10}enddeffunc_none(hash)# Check and return true if none of the values within the hash are nil# If any value contains nil, return false.hash.none?{|key,value|value.nil?}enddeffunc_find(hash)# Check and return the first object that satisfies either of the following properties:# 1. There is a [key, value] pair where the key and value are both Integers and the value is < 20 # 2. There is a [key, value] pair where the key and value are both Strings and the value starts with `a`.hash.finddo|key,value|(key.is_a?(Integer)&&value.is_a?(Integer)&&value<20)||(key.is_a?(String)&&value.is_a?(String)&&value.start_with?('a'))endend
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby Enumerables: 'any', 'all', 'none', and 'find'
You are viewing a single comment's thread. Return to all comments →