lib/assets/javascripts/extensions.coffee in material_raingular-0.0.2.4.7.alpha vs lib/assets/javascripts/extensions.coffee in material_raingular-0.0.2.4.8

- old
+ new

@@ -1,8 +1,34 @@ +Array.prototype.empty = -> + this.length == 0 +Array.prototype.present = -> + this.length != 0 Array.prototype.min = -> return Math.min.apply(null,this) Array.prototype.max = -> return Math.max.apply(null,this) +Array.prototype.railsMap = (func)-> + args = func.match(/\|(.*)\|,(.*)/) || [] + throw 'Invalid syntax "|a|, a.b"' unless args.length == 3 + arr = [] + for obj in this + eval args[1] + '= obj' + arr.push eval args[2] + arr +Array.prototype.compact = -> + arr = [] + for i in this + arr.push(i) if !!i or i == false + arr +Array.prototype.flatten = -> + arr = [] + for l in this + if Array.isArray(l) + for i in l.flatten() + arr.push i + else + arr.push l + arr Array.prototype.sum = -> total = 0 for i in this total += parseFloat(i) if i total