Created
October 10, 2016 13:03
-
-
Save anonymous/9917b4424ed1ddc93f38ba331e97b4ea to your computer and use it in GitHub Desktop.
Method
This file contains 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
class Hello | |
def self.best_sentence(sentences,desired_words) | |
ranked_sentences = sentences.sort_by do |s| | |
s.words.length - (s.downcase.words - desired_words).length | |
end | |
ranked_sentences.last | |
end | |
def words | |
scan(/\w[\w\'\-]*/) | |
end | |
end | |
sentence = [] | |
sentence[0] = "I like ruby" | |
sentence[1] = "You like ruby" | |
sentence[2] = "We all like ruby" | |
puts Hello.best_sentence(sentence,%q{ruby test}) |
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
sentence = Array.new
sentence.push("I like ruby")
sentence.push("You like ruby")
sentence.push("I dont Java")
sentence.push("We all like ruby")
puts sentence.select { |s| s.include?("ruby")}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks better in my eyes