A very lightweight underscore, for browser apps that like to watch their weight.
Note, this is a very incomplete implementation of underscore, partly because many of underscore's functions can be found on
Object now, and also partly because I'm lazy. Pull requests for missing functions will be accepted gladly.
You can either import all of lowscore, or just the parts you need.
var _ = ;_;_;var groupBy = ;var indexBy = ;...
find (87 bytes)
var find = ;var found = ;
Looks through each value in the list, returning the first one that passes a truth test (predicate), or undefined if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list.
var even = ;2
sortBy (323 bytes)
var sortBy = ;var sorted = ;
Returns a (stably) sorted copy of list, ranked in ascending order by the results of running each value through iteratee. iteratee may also be the string name of the property to sort by (eg. length).
;5 4 6 3 1 2var stooges = name: 'moe' age: 40 name: 'larry' age: 50 name: 'curly' age: 60;;name: 'curly' age: 60 name: 'larry' age: 50 name: 'moe' age: 40;
groupBy (165 bytes)
var groupBy = ;var groups = ;
Splits a collection into sets, grouped by the result of running each value through iteratee. If iteratee is a string instead of a function, groups by the property named by iteratee on each of the values.
;1: 13 2: 21 24;3: "one" "two" 5: "three"
indexBy (144 bytes)
var indexBy = ;var index = ;
Given a list, and an iteratee function that returns a key for each element in the list (or a property name), returns an object with an index of each item. Just like groupBy, but for when you know your keys are unique.
var stooges = name: 'moe' age: 40 name: 'larry' age: 50 name: 'curly' age: 60;;"40": name: 'moe' age: 40"50": name: 'larry' age: 50"60": name: 'curly' age: 60
flatten (161 bytes)
var flatten = ;var r = ;
Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will only be flattened a single level.
;1 2 3 4;;1 2 3 4;
compact (67 bytes)
var compact = ;var a = ;
;1 2 3
without (135 bytes)
var without = ;var a = ;
Returns a copy of the array with all instances of the values removed.
;2 3 4
range (118 bytes)
var range = ;var r = ;
A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted, defaults to 0; step defaults to 1. Returns a list of integers from start (inclusive) to stop (exclusive), incremented (or decremented) by step, exclusive. Note that ranges that stop before they start are considered to be zero-length instead of negative — if you'd like a negative range, use a negative step.
;0 1 2 3 4 5 6 7 8 9;1 2 3 4 5 6 7 8 9 10;0 5 10 15 20 25;0 -1 -2 -3 -4 -5 -6 -7 -8 -9;
extend (139 bytes)
var extend = ;var destination = ;
Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.
;name: 'moe' age: 50
times (77 bytes)
var times = ;var t = ;
Invokes the given iteratee function n times. Each invocation of iteratee is called with an index argument. Produces an array of the returned values.
;'item: 0' 'item: 1' 'item: 2'
values (80 bytes)
var values = ;var t = ;
Return all of the values of the object's own properties.
;1 2 3
uniq (108 bytes)
var uniq = ;var t = ;
Remove duplicate entries from the array.
;1 2 3
zip (230 bytes)
var zip = ;var zipped = ;
Merges together the values of each of the arrays with the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes. Use with apply to pass in an array of arrays. If you're working with a matrix of nested arrays, this can be used to transpose the matrix.
_;"moe" 30 true "larry" 40 false "curly" 50 false