From 89c19b136b5882e032a63a057930da6705ea6b66 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 1 Jul 2020 16:28:02 +0200 Subject: [PATCH] Deduplicate code --- www/common/onlyoffice/inner.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index f8195885b..1207bff32 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -224,13 +224,16 @@ define([ var now = function () { return +new Date(); }; + var sortCpIndex = function (hashes) { + return Object.keys(hashes).map(Number).sort(function (a, b) { + return a-b; + }); + }; var getLastCp = function (old, i) { var hashes = old ? oldHashes : content.hashes; if (!hashes || !Object.keys(hashes).length) { return {}; } i = i || 0; - var idx = Object.keys(hashes).map(Number).sort(function (a, b) { - return a-b; - }); + var idx = sortCpIndex(hashes); var lastIndex = idx[idx.length - 1 - i]; var last = JSON.parse(JSON.stringify(hashes[lastIndex])); return last; @@ -308,9 +311,7 @@ define([ return void UI.alert(Messages.oo_saveError); } // Get the last cp idx - var all = Object.keys(content.hashes || {}).map(Number).sort(function (a, b) { - return a-b; - }); + var all = sortCpIndex(content.hashes || {}); var current = all[all.length - 1] || 0; // Get the expected cp idx var _i = Math.floor(ev.index / CHECKPOINT_INTERVAL);