From d92dfa3d81cb2851dee5ee6e3d523ad9ccb7b78d Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 8 May 2012 15:11:29 +0100 Subject: [PATCH] Some new utilities --- core/modules/utils.js | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/core/modules/utils.js b/core/modules/utils.js index 737df243e..f1acf54ec 100644 --- a/core/modules/utils.js +++ b/core/modules/utils.js @@ -14,6 +14,59 @@ This file is a bit of a dumping ground; the expectation is that most of these fu /*global $tw: false */ "use strict"; +// Check if an object has a property +exports.hop = function(object,property) { + return Object.prototype.hasOwnProperty.call(object,property); +}; + +/* +Push entries onto an array, removing them first if they already exist in the array + array: array to modify + value: a single value to push or an array of values to push +*/ +exports.pushTop = function(array,value) { + var t,p; + if($tw.utils.isArray(value)) { + // Remove any array entries that are duplicated in the new values + for(t=0; t