Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Added function to "pad" a given number with leading 0s; useful for date specification when the value is less than 10 and a two digit number is needed.

Ryan Boller247b85436467
diff --git a/js/util.js b/js/util.js
index 2ab1b5b96..3af49fdb8 100644
--- a/js/util.js
+++ b/js/util.js
@@ -37,3 +37,17 @@ SOTE.util.getJSON = function(url, args, success, failure){
error: failureHandler
});
}
+
+
+/**
+ * Function to add leading zeros to a number, if necessary
+ *
+ * @param num number to pad
+ * @param places number of 0s to add
+ *
+ * @returns formatted number as a string
+ */
+SOTE.util.zeroPad = function(num, places) {
+ var zero = places - num.toString().length + 1;
+ return Array(+(zero > 0 && zero)).join("0") + num;
+}