Sha256: d2a32df85e7410266fc05495ec4cf7846f0599bf4d9b47cb429be46bd8fa6988
Contents?: true
Size: 1.64 KB
Versions: 10
Compression:
Stored size: 1.64 KB
Contents
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 Array.prototype.includes = (entry)-> this.indexOf(entry) > -1 Array.prototype.drop = (entry)-> this.splice(this.indexOf(entry),1) String.prototype.titleize = -> return this.replace(/\_/g,' ').replace(/\b[a-z]/g, (letter)-> return letter[0].toUpperCase()) Array.prototype.pluck = (property) -> return [] if !(this && property) property = String(property) return this.map (object) -> object = Object(object) return object[property] if (object.hasOwnProperty(property)) return '' Array.prototype.unique = (filterOn) -> equiv = (first,second) -> return true if first == second return !first && !second newItems = [] for item in this item = item[filterOn] if filterOn for newItem in newItems isDuplicate = false if equiv(item,newItem) isDuplicate = true break newItems.push(item) if (!isDuplicate) return newItems
Version data entries
10 entries across 10 versions & 1 rubygems