[gnome-shell/gbsneto/icon-grid-part0: 1/6] util: Add isSorted



commit b07000926f607f50352324f7de10cfc239e746bd
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jul 4 21:05:00 2019 -0300

    util: Add isSorted
    
    This will be used by future commits to detect whether the
    icon grid is not sorted anymore, and to save the grid layout
    in case it isn't.
    
    Add a new Util.isSorted() function.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/643

 js/misc/util.js | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/js/misc/util.js b/js/misc/util.js
index bd87b33c8..83c0002ab 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -345,6 +345,16 @@ function insertSorted(array, val, cmp) {
     return pos;
 }
 
+// isSorted:
+// @array: an array of strings
+//
+// Checks if @array is sorted ascendently.
+// Returns true if it is.
+function isSorted(array, cmp) {
+    const limit = array.length - 1;
+    return array.every((value, position) => position === 0 || cmp(value, array[position - 1]) >= 0);
+}
+
 var CloseButton = GObject.registerClass(
 class CloseButton extends St.Button {
     _init(boxpointer) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]