Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Taylor, Benjamin
SCALE manual
Commits
890c9023
Commit
890c9023
authored
Aug 21, 2020
by
Batson Iii, John
Browse files
Finishing the MAVRIC section
parent
34a97df7
Changes
203
Hide whitespace changes
Inline
Side-by-side
_build/html/_static/searchtools.js
View file @
890c9023
...
...
@@ -63,6 +63,11 @@ var Search = {
htmlElement
.
innerHTML
=
htmlString
;
$
(
htmlElement
).
find
(
'
.headerlink
'
).
remove
();
docContent
=
$
(
htmlElement
).
find
(
'
[role=main]
'
)[
0
];
if
(
docContent
===
undefined
)
{
console
.
warn
(
"
Content block not found. Sphinx search tries to obtain it
"
+
"
via '[role=main]'. Could you check your theme or template.
"
);
return
""
;
}
return
docContent
.
textContent
||
docContent
.
innerText
;
},
...
...
@@ -161,8 +166,7 @@ var Search = {
objectterms
.
push
(
tmp
[
i
].
toLowerCase
());
}
if
(
$u
.
indexOf
(
stopwords
,
tmp
[
i
].
toLowerCase
())
!=
-
1
||
tmp
[
i
].
match
(
/^
\d
+$/
)
||
tmp
[
i
]
===
""
)
{
if
(
$u
.
indexOf
(
stopwords
,
tmp
[
i
].
toLowerCase
())
!=
-
1
||
tmp
[
i
]
===
""
)
{
// skip this "word"
continue
;
}
...
...
@@ -245,6 +249,8 @@ var Search = {
if
(
results
.
length
)
{
var
item
=
results
.
pop
();
var
listItem
=
$
(
'
<li style="display:none"></li>
'
);
var
requestUrl
=
""
;
var
linkUrl
=
""
;
if
(
DOCUMENTATION_OPTIONS
.
BUILDER
===
'
dirhtml
'
)
{
// dirhtml builder
var
dirname
=
item
[
0
]
+
'
/
'
;
...
...
@@ -253,15 +259,17 @@ var Search = {
}
else
if
(
dirname
==
'
index/
'
)
{
dirname
=
''
;
}
listItem
.
append
(
$
(
'
<a/>
'
).
attr
(
'
href
'
,
DOCUMENTATION_OPTIONS
.
URL_ROOT
+
dirname
+
highlightstring
+
item
[
2
]).
html
(
item
[
1
]));
requestUrl
=
DOCUMENTATION_OPTIONS
.
URL_ROOT
+
dirname
;
linkUrl
=
requestUrl
;
}
else
{
// normal html builders
listItem
.
append
(
$
(
'
<a/>
'
).
attr
(
'
href
'
,
item
[
0
]
+
DOCUMENTATION_OPTIONS
.
FILE_SUFFIX
+
highlightstring
+
item
[
2
]).
html
(
item
[
1
]));
requestUrl
=
DOCUMENTATION_OPTIONS
.
URL_ROOT
+
item
[
0
]
+
DOCUMENTATION_OPTIONS
.
FILE_SUFFIX
;
linkUrl
=
item
[
0
]
+
DOCUMENTATION_OPTIONS
.
LINK_SUFFIX
;
}
listItem
.
append
(
$
(
'
<a/>
'
).
attr
(
'
href
'
,
linkUrl
+
highlightstring
+
item
[
2
]).
html
(
item
[
1
]));
if
(
item
[
3
])
{
listItem
.
append
(
$
(
'
<span> (
'
+
item
[
3
]
+
'
)</span>
'
));
Search
.
output
.
append
(
listItem
);
...
...
@@ -269,7 +277,7 @@ var Search = {
displayNextItem
();
});
}
else
if
(
DOCUMENTATION_OPTIONS
.
HAS_SOURCE
)
{
$
.
ajax
({
url
:
DOCUMENTATION_OPTIONS
.
URL_ROOT
+
item
[
0
]
+
DOCUMENTATION_OPTIONS
.
FILE_SUFFIX
,
$
.
ajax
({
url
:
requestUrl
,
dataType
:
"
text
"
,
complete
:
function
(
jqxhr
,
textstatus
)
{
var
data
=
jqxhr
.
responseText
;
...
...
_build/html/_static/underscore-1.3.1 (1).js
deleted
100644 → 0
View file @
34a97df7
// Underscore.js 1.3.1
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
// For all details and documentation:
// http://documentcloud.github.com/underscore
(
function
()
{
// Baseline setup
// --------------
// Establish the root object, `window` in the browser, or `global` on the server.
var
root
=
this
;
// Save the previous value of the `_` variable.
var
previousUnderscore
=
root
.
_
;
// Establish the object that gets returned to break out of a loop iteration.
var
breaker
=
{};
// Save bytes in the minified (but not gzipped) version:
var
ArrayProto
=
Array
.
prototype
,
ObjProto
=
Object
.
prototype
,
FuncProto
=
Function
.
prototype
;
// Create quick reference variables for speed access to core prototypes.
var
slice
=
ArrayProto
.
slice
,
unshift
=
ArrayProto
.
unshift
,
toString
=
ObjProto
.
toString
,
hasOwnProperty
=
ObjProto
.
hasOwnProperty
;
// All **ECMAScript 5** native function implementations that we hope to use
// are declared here.
var
nativeForEach
=
ArrayProto
.
forEach
,
nativeMap
=
ArrayProto
.
map
,
nativeReduce
=
ArrayProto
.
reduce
,
nativeReduceRight
=
ArrayProto
.
reduceRight
,
nativeFilter
=
ArrayProto
.
filter
,
nativeEvery
=
ArrayProto
.
every
,
nativeSome
=
ArrayProto
.
some
,
nativeIndexOf
=
ArrayProto
.
indexOf
,
nativeLastIndexOf
=
ArrayProto
.
lastIndexOf
,
nativeIsArray
=
Array
.
isArray
,
nativeKeys
=
Object
.
keys
,
nativeBind
=
FuncProto
.
bind
;
// Create a safe reference to the Underscore object for use below.
var
_
=
function
(
obj
)
{
return
new
wrapper
(
obj
);
};
// Export the Underscore object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, add `_` as a global object via a string identifier,
// for Closure Compiler "advanced" mode.
if
(
typeof
exports
!==
'
undefined
'
)
{
if
(
typeof
module
!==
'
undefined
'
&&
module
.
exports
)
{
exports
=
module
.
exports
=
_
;
}
exports
.
_
=
_
;
}
else
{
root
[
'
_
'
]
=
_
;
}
// Current version.
_
.
VERSION
=
'
1.3.1
'
;
// Collection Functions
// --------------------
// The cornerstone, an `each` implementation, aka `forEach`.
// Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available.
var
each
=
_
.
each
=
_
.
forEach
=
function
(
obj
,
iterator
,
context
)
{
if
(
obj
==
null
)
return
;
if
(
nativeForEach
&&
obj
.
forEach
===
nativeForEach
)
{
obj
.
forEach
(
iterator
,
context
);
}
else
if
(
obj
.
length
===
+
obj
.
length
)
{
for
(
var
i
=
0
,
l
=
obj
.
length
;
i
<
l
;
i
++
)
{
if
(
i
in
obj
&&
iterator
.
call
(
context
,
obj
[
i
],
i
,
obj
)
===
breaker
)
return
;
}
}
else
{
for
(
var
key
in
obj
)
{
if
(
_
.
has
(
obj
,
key
))
{
if
(
iterator
.
call
(
context
,
obj
[
key
],
key
,
obj
)
===
breaker
)
return
;
}
}
}
};
// Return the results of applying the iterator to each element.
// Delegates to **ECMAScript 5**'s native `map` if available.
_
.
map
=
_
.
collect
=
function
(
obj
,
iterator
,
context
)
{
var
results
=
[];
if
(
obj
==
null
)
return
results
;
if
(
nativeMap
&&
obj
.
map
===
nativeMap
)
return
obj
.
map
(
iterator
,
context
);
each
(
obj
,
function
(
value
,
index
,
list
)
{
results
[
results
.
length
]
=
iterator
.
call
(
context
,
value
,
index
,
list
);
});
if
(
obj
.
length
===
+
obj
.
length
)
results
.
length
=
obj
.
length
;
return
results
;
};
// **Reduce** builds up a single result from a list of values, aka `inject`,
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
_
.
reduce
=
_
.
foldl
=
_
.
inject
=
function
(
obj
,
iterator
,
memo
,
context
)
{
var
initial
=
arguments
.
length
>
2
;
if
(
obj
==
null
)
obj
=
[];
if
(
nativeReduce
&&
obj
.
reduce
===
nativeReduce
)
{
if
(
context
)
iterator
=
_
.
bind
(
iterator
,
context
);
return
initial
?
obj
.
reduce
(
iterator
,
memo
)
:
obj
.
reduce
(
iterator
);
}
each
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
!
initial
)
{
memo
=
value
;
initial
=
true
;
}
else
{
memo
=
iterator
.
call
(
context
,
memo
,
value
,
index
,
list
);
}
});
if
(
!
initial
)
throw
new
TypeError
(
'
Reduce of empty array with no initial value
'
);
return
memo
;
};
// The right-associative version of reduce, also known as `foldr`.
// Delegates to **ECMAScript 5**'s native `reduceRight` if available.
_
.
reduceRight
=
_
.
foldr
=
function
(
obj
,
iterator
,
memo
,
context
)
{
var
initial
=
arguments
.
length
>
2
;
if
(
obj
==
null
)
obj
=
[];
if
(
nativeReduceRight
&&
obj
.
reduceRight
===
nativeReduceRight
)
{
if
(
context
)
iterator
=
_
.
bind
(
iterator
,
context
);
return
initial
?
obj
.
reduceRight
(
iterator
,
memo
)
:
obj
.
reduceRight
(
iterator
);
}
var
reversed
=
_
.
toArray
(
obj
).
reverse
();
if
(
context
&&
!
initial
)
iterator
=
_
.
bind
(
iterator
,
context
);
return
initial
?
_
.
reduce
(
reversed
,
iterator
,
memo
,
context
)
:
_
.
reduce
(
reversed
,
iterator
);
};
// Return the first value which passes a truth test. Aliased as `detect`.
_
.
find
=
_
.
detect
=
function
(
obj
,
iterator
,
context
)
{
var
result
;
any
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
iterator
.
call
(
context
,
value
,
index
,
list
))
{
result
=
value
;
return
true
;
}
});
return
result
;
};
// Return all the elements that pass a truth test.
// Delegates to **ECMAScript 5**'s native `filter` if available.
// Aliased as `select`.
_
.
filter
=
_
.
select
=
function
(
obj
,
iterator
,
context
)
{
var
results
=
[];
if
(
obj
==
null
)
return
results
;
if
(
nativeFilter
&&
obj
.
filter
===
nativeFilter
)
return
obj
.
filter
(
iterator
,
context
);
each
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
iterator
.
call
(
context
,
value
,
index
,
list
))
results
[
results
.
length
]
=
value
;
});
return
results
;
};
// Return all the elements for which a truth test fails.
_
.
reject
=
function
(
obj
,
iterator
,
context
)
{
var
results
=
[];
if
(
obj
==
null
)
return
results
;
each
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
!
iterator
.
call
(
context
,
value
,
index
,
list
))
results
[
results
.
length
]
=
value
;
});
return
results
;
};
// Determine whether all of the elements match a truth test.
// Delegates to **ECMAScript 5**'s native `every` if available.
// Aliased as `all`.
_
.
every
=
_
.
all
=
function
(
obj
,
iterator
,
context
)
{
var
result
=
true
;
if
(
obj
==
null
)
return
result
;
if
(
nativeEvery
&&
obj
.
every
===
nativeEvery
)
return
obj
.
every
(
iterator
,
context
);
each
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
!
(
result
=
result
&&
iterator
.
call
(
context
,
value
,
index
,
list
)))
return
breaker
;
});
return
result
;
};
// Determine if at least one element in the object matches a truth test.
// Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`.
var
any
=
_
.
some
=
_
.
any
=
function
(
obj
,
iterator
,
context
)
{
iterator
||
(
iterator
=
_
.
identity
);
var
result
=
false
;
if
(
obj
==
null
)
return
result
;
if
(
nativeSome
&&
obj
.
some
===
nativeSome
)
return
obj
.
some
(
iterator
,
context
);
each
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
result
||
(
result
=
iterator
.
call
(
context
,
value
,
index
,
list
)))
return
breaker
;
});
return
!!
result
;
};
// Determine if a given value is included in the array or object using `===`.
// Aliased as `contains`.
_
.
include
=
_
.
contains
=
function
(
obj
,
target
)
{
var
found
=
false
;
if
(
obj
==
null
)
return
found
;
if
(
nativeIndexOf
&&
obj
.
indexOf
===
nativeIndexOf
)
return
obj
.
indexOf
(
target
)
!=
-
1
;
found
=
any
(
obj
,
function
(
value
)
{
return
value
===
target
;
});
return
found
;
};
// Invoke a method (with arguments) on every item in a collection.
_
.
invoke
=
function
(
obj
,
method
)
{
var
args
=
slice
.
call
(
arguments
,
2
);
return
_
.
map
(
obj
,
function
(
value
)
{
return
(
_
.
isFunction
(
method
)
?
method
||
value
:
value
[
method
]).
apply
(
value
,
args
);
});
};
// Convenience version of a common use case of `map`: fetching a property.
_
.
pluck
=
function
(
obj
,
key
)
{
return
_
.
map
(
obj
,
function
(
value
){
return
value
[
key
];
});
};
// Return the maximum element or (element-based computation).
_
.
max
=
function
(
obj
,
iterator
,
context
)
{
if
(
!
iterator
&&
_
.
isArray
(
obj
))
return
Math
.
max
.
apply
(
Math
,
obj
);
if
(
!
iterator
&&
_
.
isEmpty
(
obj
))
return
-
Infinity
;
var
result
=
{
computed
:
-
Infinity
};
each
(
obj
,
function
(
value
,
index
,
list
)
{
var
computed
=
iterator
?
iterator
.
call
(
context
,
value
,
index
,
list
)
:
value
;
computed
>=
result
.
computed
&&
(
result
=
{
value
:
value
,
computed
:
computed
});
});
return
result
.
value
;
};
// Return the minimum element (or element-based computation).
_
.
min
=
function
(
obj
,
iterator
,
context
)
{
if
(
!
iterator
&&
_
.
isArray
(
obj
))
return
Math
.
min
.
apply
(
Math
,
obj
);
if
(
!
iterator
&&
_
.
isEmpty
(
obj
))
return
Infinity
;
var
result
=
{
computed
:
Infinity
};
each
(
obj
,
function
(
value
,
index
,
list
)
{
var
computed
=
iterator
?
iterator
.
call
(
context
,
value
,
index
,
list
)
:
value
;
computed
<
result
.
computed
&&
(
result
=
{
value
:
value
,
computed
:
computed
});
});
return
result
.
value
;
};
// Shuffle an array.
_
.
shuffle
=
function
(
obj
)
{
var
shuffled
=
[],
rand
;
each
(
obj
,
function
(
value
,
index
,
list
)
{
if
(
index
==
0
)
{
shuffled
[
0
]
=
value
;
}
else
{
rand
=
Math
.
floor
(
Math
.
random
()
*
(
index
+
1
));
shuffled
[
index
]
=
shuffled
[
rand
];
shuffled
[
rand
]
=
value
;
}
});
return
shuffled
;
};
// Sort the object's values by a criterion produced by an iterator.
_
.
sortBy
=
function
(
obj
,
iterator
,
context
)
{
return
_
.
pluck
(
_
.
map
(
obj
,
function
(
value
,
index
,
list
)
{
return
{
value
:
value
,
criteria
:
iterator
.
call
(
context
,
value
,
index
,
list
)
};
}).
sort
(
function
(
left
,
right
)
{
var
a
=
left
.
criteria
,
b
=
right
.
criteria
;
return
a
<
b
?
-
1
:
a
>
b
?
1
:
0
;
}),
'
value
'
);
};
// Groups the object's values by a criterion. Pass either a string attribute
// to group by, or a function that returns the criterion.
_
.
groupBy
=
function
(
obj
,
val
)
{
var
result
=
{};
var
iterator
=
_
.
isFunction
(
val
)
?
val
:
function
(
obj
)
{
return
obj
[
val
];
};
each
(
obj
,
function
(
value
,
index
)
{
var
key
=
iterator
(
value
,
index
);
(
result
[
key
]
||
(
result
[
key
]
=
[])).
push
(
value
);
});
return
result
;
};
// Use a comparator function to figure out at what index an object should
// be inserted so as to maintain order. Uses binary search.
_
.
sortedIndex
=
function
(
array
,
obj
,
iterator
)
{
iterator
||
(
iterator
=
_
.
identity
);
var
low
=
0
,
high
=
array
.
length
;
while
(
low
<
high
)
{
var
mid
=
(
low
+
high
)
>>
1
;
iterator
(
array
[
mid
])
<
iterator
(
obj
)
?
low
=
mid
+
1
:
high
=
mid
;
}
return
low
;
};
// Safely convert anything iterable into a real, live array.
_
.
toArray
=
function
(
iterable
)
{
if
(
!
iterable
)
return
[];
if
(
iterable
.
toArray
)
return
iterable
.
toArray
();
if
(
_
.
isArray
(
iterable
))
return
slice
.
call
(
iterable
);
if
(
_
.
isArguments
(
iterable
))
return
slice
.
call
(
iterable
);
return
_
.
values
(
iterable
);
};
// Return the number of elements in an object.
_
.
size
=
function
(
obj
)
{
return
_
.
toArray
(
obj
).
length
;
};
// Array Functions
// ---------------
// Get the first element of an array. Passing **n** will return the first N
// values in the array. Aliased as `head`. The **guard** check allows it to work
// with `_.map`.
_
.
first
=
_
.
head
=
function
(
array
,
n
,
guard
)
{
return
(
n
!=
null
)
&&
!
guard
?
slice
.
call
(
array
,
0
,
n
)
:
array
[
0
];
};
// Returns everything but the last entry of the array. Especcialy useful on
// the arguments object. Passing **n** will return all the values in
// the array, excluding the last N. The **guard** check allows it to work with
// `_.map`.
_
.
initial
=
function
(
array
,
n
,
guard
)
{
return
slice
.
call
(
array
,
0
,
array
.
length
-
((
n
==
null
)
||
guard
?
1
:
n
));
};
// Get the last element of an array. Passing **n** will return the last N
// values in the array. The **guard** check allows it to work with `_.map`.
_
.
last
=
function
(
array
,
n
,
guard
)
{
if
((
n
!=
null
)
&&
!
guard
)
{
return
slice
.
call
(
array
,
Math
.
max
(
array
.
length
-
n
,
0
));
}
else
{
return
array
[
array
.
length
-
1
];
}
};
// Returns everything but the first entry of the array. Aliased as `tail`.
// Especially useful on the arguments object. Passing an **index** will return
// the rest of the values in the array from that index onward. The **guard**
// check allows it to work with `_.map`.
_
.
rest
=
_
.
tail
=
function
(
array
,
index
,
guard
)
{
return
slice
.
call
(
array
,
(
index
==
null
)
||
guard
?
1
:
index
);
};
// Trim out all falsy values from an array.
_
.
compact
=
function
(
array
)
{
return
_
.
filter
(
array
,
function
(
value
){
return
!!
value
;
});
};
// Return a completely flattened version of an array.
_
.
flatten
=
function
(
array
,
shallow
)
{
return
_
.
reduce
(
array
,
function
(
memo
,
value
)
{
if
(
_
.
isArray
(
value
))
return
memo
.
concat
(
shallow
?
value
:
_
.
flatten
(
value
));
memo
[
memo
.
length
]
=
value
;
return
memo
;
},
[]);
};
// Return a version of the array that does not contain the specified value(s).
_
.
without
=
function
(
array
)
{
return
_
.
difference
(
array
,
slice
.
call
(
arguments
,
1
));
};
// Produce a duplicate-free version of the array. If the array has already
// been sorted, you have the option of using a faster algorithm.
// Aliased as `unique`.
_
.
uniq
=
_
.
unique
=
function
(
array
,
isSorted
,
iterator
)
{
var
initial
=
iterator
?
_
.
map
(
array
,
iterator
)
:
array
;
var
result
=
[];
_
.
reduce
(
initial
,
function
(
memo
,
el
,
i
)
{
if
(
0
==
i
||
(
isSorted
===
true
?
_
.
last
(
memo
)
!=
el
:
!
_
.
include
(
memo
,
el
)))
{
memo
[
memo
.
length
]
=
el
;
result
[
result
.
length
]
=
array
[
i
];
}
return
memo
;
},
[]);
return
result
;
};
// Produce an array that contains the union: each distinct element from all of
// the passed-in arrays.
_
.
union
=
function
()
{
return
_
.
uniq
(
_
.
flatten
(
arguments
,
true
));
};
// Produce an array that contains every item shared between all the
// passed-in arrays. (Aliased as "intersect" for back-compat.)
_
.
intersection
=
_
.
intersect
=
function
(
array
)
{
var
rest
=
slice
.
call
(
arguments
,
1
);
return
_
.
filter
(
_
.
uniq
(
array
),
function
(
item
)
{
return
_
.
every
(
rest
,
function
(
other
)
{
return
_
.
indexOf
(
other
,
item
)
>=
0
;
});
});
};
// Take the difference between one array and a number of other arrays.
// Only the elements present in just the first array will remain.
_
.
difference
=
function
(
array
)
{
var
rest
=
_
.
flatten
(
slice
.
call
(
arguments
,
1
));
return
_
.
filter
(
array
,
function
(
value
){
return
!
_
.
include
(
rest
,
value
);
});
};
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_
.
zip
=
function
()
{
var
args
=
slice
.
call
(
arguments
);
var
length
=
_
.
max
(
_
.
pluck
(
args
,
'
length
'
));
var
results
=
new
Array
(
length
);
for
(
var
i
=
0
;
i
<
length
;
i
++
)
results
[
i
]
=
_
.
pluck
(
args
,
""
+
i
);
return
results
;
};
// If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
// we need this function. Return the position of the first occurrence of an
// item in an array, or -1 if the item is not included in the array.
// Delegates to **ECMAScript 5**'s native `indexOf` if available.
// If the array is large and already in sort order, pass `true`
// for **isSorted** to use binary search.
_
.
indexOf
=
function
(
array
,
item
,
isSorted
)
{
if
(
array
==
null
)
return
-
1
;
var
i
,
l
;
if
(
isSorted
)
{
i
=
_
.
sortedIndex
(
array
,
item
);
return
array
[
i
]
===
item
?
i
:
-
1
;
}
if
(
nativeIndexOf
&&
array
.
indexOf
===
nativeIndexOf
)
return
array
.
indexOf
(
item
);
for
(
i
=
0
,
l
=
array
.
length
;
i
<
l
;
i
++
)
if
(
i
in
array
&&
array
[
i
]
===
item
)
return
i
;
return
-
1
;
};
// Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
_
.
lastIndexOf
=
function
(
array
,
item
)
{
if
(
array
==
null
)
return
-
1
;
if
(
nativeLastIndexOf
&&
array
.
lastIndexOf
===
nativeLastIndexOf
)
return
array
.
lastIndexOf
(
item
);
var
i
=
array
.
length
;
while
(
i
--
)
if
(
i
in
array
&&
array
[
i
]
===
item
)
return
i
;
return
-
1
;
};
// Generate an integer Array containing an arithmetic progression. A port of
// the native Python `range()` function. See
// [the Python documentation](http://docs.python.org/library/functions.html#range).
_
.
range
=
function
(
start
,
stop
,
step
)
{
if
(
arguments
.
length
<=
1
)
{
stop
=
start
||
0
;
start
=
0
;
}
step
=
arguments
[
2
]
||
1
;
var
len
=
Math
.
max
(
Math
.
ceil
((
stop
-
start
)
/
step
),
0
);
var
idx
=
0
;
var
range
=
new
Array
(
len
);
while
(
idx
<
len
)
{
range
[
idx
++
]
=
start
;
start
+=
step
;
}
return
range
;
};
// Function (ahem) Functions
// ------------------
// Reusable constructor function for prototype setting.
var
ctor
=
function
(){};
// Create a function bound to a given object (assigning `this`, and arguments,
// optionally). Binding with arguments is also known as `curry`.
// Delegates to **ECMAScript 5**'s native `Function.bind` if available.
// We check for `func.bind` first, to fail fast when `func` is undefined.
_
.
bind
=
function
bind
(
func
,
context
)
{
var
bound
,
args
;
if
(
func
.
bind
===
nativeBind
&&
nativeBind
)
return
nativeBind
.
apply
(
func
,
slice
.
call
(
arguments
,
1
));
if
(
!
_
.
isFunction
(
func
))
throw
new
TypeError
;
args
=
slice
.
call
(
arguments
,
2
);
return
bound
=
function
()
{
if
(
!
(
this
instanceof
bound
))
return
func
.
apply
(
context
,
args
.
concat
(
slice
.
call
(
arguments
)));
ctor
.
prototype
=
func
.
prototype
;
var
self
=
new
ctor
;
var
result
=
func
.
apply
(
self
,
args
.
concat
(
slice
.
call
(
arguments
)));
if
(
Object
(
result
)
===
result
)
return
result
;
return
self
;
};
};
// Bind all of an object's methods to that object. Useful for ensuring that
// all callbacks defined on an object belong to it.
_
.
bindAll
=
function
(
obj
)
{
var
funcs
=
slice
.
call
(
arguments
,
1
);
if
(
funcs
.
length
==
0
)
funcs
=
_
.
functions
(
obj
);
each
(
funcs
,
function
(
f
)
{
obj
[
f
]
=
_
.
bind
(
obj
[
f
],
obj
);
});
return
obj
;
};
// Memoize an expensive function by storing its results.
_
.
memoize
=
function
(
func
,
hasher
)
{
var
memo
=
{};
hasher
||
(
hasher
=
_
.
identity
);
return
function
()
{
var
key
=
hasher
.
apply
(
this
,
arguments
);
return
_
.
has
(
memo
,
key
)
?
memo
[
key
]
:
(
memo
[
key
]
=
func
.
apply
(
this
,
arguments
));
};
};