From 6d9d071b2f3c0d375517163005ff27a04383c4d6 Mon Sep 17 00:00:00 2001 From: Pier Paolo Ramon Date: Wed, 5 Oct 2011 14:06:18 +0200 Subject: [PATCH] Implemented _.init as per #319 --- underscore.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/underscore.js b/underscore.js index 0db66d0b6..dfc875d3a 100644 --- a/underscore.js +++ b/underscore.js @@ -323,6 +323,14 @@ return slice.call(array, (index == null) || guard ? 1 : index); }; + // 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`. + _.init = 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) {