This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rspec' | |
module Enumerable | |
def myinject (base = nil, &block) | |
return nil if block.nil? | |
return nil if self.length.zero? | |
if base.nil? | |
case self.first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run using jasmine-node. | |
// e.g.: jasmine-node file_name.spec.js | |
Array.prototype.mymap = function (callback) { | |
var obj = Object(this); | |
if (obj.length === 0) return null; | |
if (typeof(callback) === 'undefined') return null; | |
for (var i = 0, o; o = obj[i]; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run using rspec. | |
# e.g.: rspec file_name.rb | |
require 'rubygems' | |
require 'rspec' | |
module Enumerable | |
def mymap (&block) | |
return nil if block.nil? |
NewerOlder