Skip to content

Instantly share code, notes, and snippets.

Created October 10, 2016 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9917b4424ed1ddc93f38ba331e97b4ea to your computer and use it in GitHub Desktop.
Save anonymous/9917b4424ed1ddc93f38ba331e97b4ea to your computer and use it in GitHub Desktop.
Method
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})
@SebastianThorn
Copy link

SebastianThorn commented Oct 10, 2016

sentence = Array.new
sentence.push("I like ruby")
sentence.push("You like ruby")
sentence.push("We all like ruby")

looks better in my eyes

@SebastianThorn
Copy link

#! /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