Skip to content

Commit 36e93f1

Browse files
author
Rad
committed
Ruby
1 parent 20db2bb commit 36e93f1

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Ruby/README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,47 @@ names.select {|word| word.length > 5 }
2929
'RubyMonk Is Pretty Brilliant'.gsub(/[A-Z]/, '0')
3030
'RubyMonk Is Pretty Brilliant'.match(/ ./, 9)
3131

32-
Boolean
32+
####Boolean
3333
!(name=='Bob')
34+
```
35+
###Examples
3436

37+
```ruby
3538
def sort_string(string)
3639
string.split(' ').sort{|x, y| x.length <=> y.length}.join(' ')
3740
end
3841

42+
def random_select(array, n)
43+
result = []
44+
n.times do
45+
result << array[rand(array.length)]
46+
end
47+
result
48+
end
49+
50+
is_an_experienced_ruby_programmer =
51+
(candidate.languages_worked_with.include? 'Ruby') &&
52+
(candidate.years_of_experience >= 2 || candidate.github_points >= 500) &&
53+
! (candidate.age < 15 || candidate.applied_recently?)
54+
55+
def palindrome?(sentence)
56+
s = sentence.downcase.gsub(" ","")
57+
s == s.reverse
58+
end
59+
60+
def sum_of_cubes(a, b)
61+
(a..b).inject(0) { |sum, x| sum += (x*x*x) }
62+
end
63+
64+
def non_duplicated_values(values)
65+
unique = []
66+
values.map do |i|
67+
if values.count(i) < 2
68+
unique << i
69+
end
70+
end
71+
unique
72+
endef sort_string(string)
73+
string.split(' ').sort{|x, y| x.length <=> y.length}.join(' ')
74+
end
3975
```

0 commit comments

Comments
 (0)