Created
December 15, 2010 18:59
-
-
Save orlin/742422 to your computer and use it in GitHub Desktop.
Revisions
-
Orlin M Bozhinov revised this gist
Jan 13, 2011 . 2 changed files with 49 additions and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,23 @@ define (require, exports, module) -> _ = require("underscore") _.mixin require("underscore.string") _.mixin # Converts the arguments list to an Array aToArr: (list) -> if _.isArguments(list) _.toArray(list).slice(0) else console.log "aToArr called with these non-arguments: #{list}" [list] # Merges all from a list of objects in return for a single one # sequentially overwrites keys (with disrespect for nested values) allFurther: (into, rest...) -> # _.each rest, (item) -> _.map item, (val, key) -> into[key] = val for item in rest for key, val of item into[key] = val into module.exports = _ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ var __slice = Array.prototype.slice; define(function(require, exports, module) { var _; _ = require("underscore"); _.mixin(require("underscore.string")); _.mixin({ aToArr: function(list) { if (_.isArguments(list)) { return _.toArray(list).slice(0); } else { console.log("aToArr called with these non-arguments: " + list); return [list]; } }, allFurther: function() { var into, item, key, rest, val, _i, _len; into = arguments[0], rest = 2 <= arguments.length ? __slice.call(arguments, 1) : []; for (_i = 0, _len = rest.length; _i < _len; _i++) { item = rest[_i]; for (key in item) { val = item[key]; into[key] = val; } } return into; } }); return module.exports = _; }); -
Orlin M Bozhinov revised this gist
Dec 15, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ _.mixin # Merges all from a list of objects in return for a single one # sequentially overwrites keys (with disrespect for nested values) allFurther: (into, rest...) -> for item in rest for key, val of item into[key] = val -
Orlin M Bozhinov revised this gist
Dec 15, 2010 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,19 +2,18 @@ _ = require("underscore") _.mixin require("underscore.strings") _.mixin # Converts the arguments list to an Array aToArr: (list) -> if _.isArguments(list) _.toArray(list).slice(0) else console.log "aToArr called with these non-arguments: #{list}" [list] # Merges all from a list of objects in return for a single one # sequentially overwrites keys (with disrespect for nested values) oneForAll: (into, rest...) -> for item in rest for key, val of item into[key] = val into -
Orlin M Bozhinov created this gist
Dec 15, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ _ = require("underscore") _.mixin require("underscore.strings") _.mixin # Converts arguments to plain Array aToArr: (list) -> if _.isArguments(list) _.toArray(list).slice(0)[0] else console.log "aToArr called with these non-arguments: #{list}" [list] # Merges an array of objects (sequentially overwrites with disrespect for nested values) merge: -> args = _(arguments).aToArr() into = _.first args for item in _.rest args for key, val of item into[key] = val into module.exports = _