diff --git a/sorting_algos.rb b/sorting_algos.rb index e9611e2..0bdb6a2 100644 --- a/sorting_algos.rb +++ b/sorting_algos.rb @@ -22,18 +22,19 @@ def compare_to(sortings) end - if defined? third - "if (#{(comp first)[:if]}) { - return #{(comp first)[:ret]}; - } else if (#{(comp second)[:if]}) { - return #{(comp second)[:ret]}; - } - return #{(comp third)[:ret]};" - else - "if (#{(comp first)[:if]}) { - return #{(comp first)[:ret]}; - } - return #{(comp second)[:ret]}; - " + pls = sortings.slice(1,sortings.length - 2).map do |ele| + " else if (#{(comp ele)[:if]}) { + return #{(comp ele)[:ret]}; + }" end + + + + + "if (#{(comp first)[:if]}) { + return #{(comp first)[:ret]}; + } + #{pls.join "\n"} + return #{(comp sortings[sortings.length-1])[:ret]};" + end \ No newline at end of file