Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 6c537bc

Browse files
author
James Zhang
committed
More solutions. Ruby makes it easy
1 parent 6da15c4 commit 6c537bc

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

factorial/factorial.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def factorial(n)
2+
return 1 if n < 2
3+
n * factorial(n - 1)
4+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def multiples_of_three_and_five
2+
(1...1000).to_a.select { |num| num % 3 == 0 || num % 5 == 0 }.reduce(&:+)
3+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def odd_occuring_element(array)
2+
array.uniq.each do |num|
3+
return num if array.count(num) % 2 != 0
4+
end
5+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def remove_duplicates(str)
2+
str.split("").uniq.join
3+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def reverse_words(array)
2+
array.split(" ").reverse.join(" ")
3+
end

0 commit comments

Comments
 (0)