Skip to content

Commit 8e477f5

Browse files
committed
First commit. Added identity and last.
1 parent c3c426c commit 8e477f5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/underbar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var _ = {};
88
// seem very useful, but remember it--if a function needs to provide an
99
// iterator when the user does not pass one in, this will be handy.
1010
_.identity = function(val) {
11+
return val;
1112
};
1213

1314
/**
@@ -38,6 +39,9 @@ var _ = {};
3839
// Like first, but for the last elements. If n is undefined, return just the
3940
// last element.
4041
_.last = function(array, n) {
42+
return n === undefined ? array[array.length-1] :
43+
n>=array.length ? array :
44+
array.slice(array.length-n, array.length);
4145
};
4246

4347
// Call iterator(value, key, collection) for each element of collection.

0 commit comments

Comments
 (0)