Ad
Recursion
Algorithms
Computability Theory
Logic
Theoretical Computer Science
Arrays
Data Types
Methods
Functions
Object-oriented Programming
Control Flow
Basic Language Features
Fundamentals
Programming Paradigms
Classes
Code
Diff
  • class Array # Opens up the Array class for method creation
      def flip
        self.reverse.map{|e| e.is_a?(Array) ? e.flip : e}
      end
    end
    • class Array # Opens up the Array class for method creation
    • def flip
    • result = []
    • me = self.reverse # Don't fret, I'll sort the Arrays out!
    • me.each do |x|
    • if x.class == Array then result << x.flip # Here's the recursion.
    • else result << x
    • end
    • end
    • return result
    • self.reverse.map{|e| e.is_a?(Array) ? e.flip : e}
    • end
    • end