Skip to content

Instantly share code, notes, and snippets.

View jeffchao's full-sized avatar
:shipit:

Jeff Chao jeffchao

:shipit:
View GitHub Profile
@jeffchao
jeffchao / injectable.rb
Created March 29, 2013 06:19
Basic implementation of Enumerable.inject() in Ruby
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
@jeffchao
jeffchao / mappable.spec.js
Created March 28, 2013 23:58
Implementation of Array.prototype.map() in Javascript
// 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++) {
@jeffchao
jeffchao / mappable.rb
Last active February 2, 2020 04:05
Implementation of Enumerable.map() in Ruby
# Run using rspec.
# e.g.: rspec file_name.rb
require 'rubygems'
require 'rspec'
module Enumerable
def mymap (&block)
return nil if block.nil?