Total Blog Views: 62
Blog Status: publish
Created By: swazahmad Created at: 04-22-2022
Tags: ruby rails intervoew question 2022 ruby interview question program tricky 2022 lattest ruby sample program for interviews 2022
1. Make the Below Array sorted and combined into one array
[1,2,2,[2,4,5],[44,55,[45,77]]]
Answer
[1,2,2,[2,4,5],[44,55,[45,77]]].flatten.sort [1, 2, 2, 2, 4, 5, 44, 45, 55, 77]
2. Find the occurrence of vowel([a e i o u]) in string and map the occurrence in hash for example Below
"SDFGHJKLKJHQWERTYUIZXCVBNM GFHHJLJJGQWERTYUASDFGHJKZXCVBNM fdshkjhsfd IUYygdshdg fsdndsfk"
{a: 1, e: 5}
Answer:
"SDFGHJKLKJHQWERTYUIZXCVBNM GFHHJLJJGQWERTYUASDFGHJKZXCVBNM fdshkjhsfd IUYygdshdg fsdndsfk".downcase.scan(/[a e i o u]/).inject(Hash.new(0)){|h, c| h[c] += 1; h} Output ==> {"e"=>2, "u"=>3, "i"=>2, " "=>4, "a"=>1}
3. Replace censored word from array of string
list_posts = [ "This summer sucks!", "I hate this Office House!", "I can't believe we're living with such a bad enviroment. We were so foolish", "Smoker are danger to society. I hate that he's so bad – it sucks.", ]
List of Bad words
bad_word = ["sucks", "bad", "hate", "foolish", "danger to society"]
If banned Texts come to need to replace with "####"
Answer:
list_post.map {|post| post.gsub!(Regexp.union(bad_word),'####')} Output ==> ["This summer ####!", "I #### this Office House!", "I can't believe we're living with such a #### enviroment. We were so ####", "Smoker are ####. I #### that he's so #### – it ####."]Thanks in advance
we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.
© Copyright Shadbox. All Rights Reserved
Rate Blog :
Share on :
Do you have any blog suggestion? please click on the link