Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions koodi.rb
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# kirjoita koodi tänne
def luokittelu(taulukko)
positiivinen = []
negatiivinen = []
parillinen = []
pariton = []
taulukko.each do |x|
if x > 0 then positiivinen.push(x) end
if x < 0 then negatiivinen.push(x) end
if x % 2 == 0 then parillinen.push(x) else pariton.push(x) end
end
summa = taulukko.inject(:+)
if (summa == nil) then summa = 0 end
{negatiivinen: negatiivinen.sort, positiivinen: positiivinen.sort, parillinen: parillinen.sort, pariton: pariton.sort, summa: summa}
end