From 42c60913c6948c435a511afb4c3c738ab2d113d3 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 28 Mar 2011 13:14:25 +0200 Subject: [PATCH] add firstObject method to CPArray --- Foundation/CPArray/CPArray.j | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Foundation/CPArray/CPArray.j b/Foundation/CPArray/CPArray.j index e6a7a5978..cd804043f 100755 --- a/Foundation/CPArray/CPArray.j +++ b/Foundation/CPArray/CPArray.j @@ -205,7 +205,20 @@ var concat = Array.prototype.concat, } /*! - Returns the last object in the array. If the array is empty, returns \c nil/ + Returns the first object in the array. If the array is empty, returns \c nil +*/ +- (id)firstObject +{ + var count = [self count]; + + if (count > 0) + return [self objectAtIndex:0]; + + return nil; +} + +/*! + Returns the last object in the array. If the array is empty, returns \c nil */ - (id)lastObject {