[gnome-shell/gbsneto/icon-grid-dnd: 50/96] util: Add isSorted
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gbsneto/icon-grid-dnd: 50/96] util: Add isSorted
- Date: Tue, 16 Jul 2019 23:26:20 +0000 (UTC)
commit 6a3606cf2e8c2092918c811d035b28dde7633de7
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/603
js/misc/util.js | 10 ++++++++++
1 file changed, 10 insertions(+)
---
diff --git a/js/misc/util.js b/js/misc/util.js
index b97218e07..8a57e06bb 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -342,6 +342,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]