From 49a84e66996cb5c1604da1152989dd84ea8bf636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AE=B6=E8=BD=B6?= <117028813@qq.com> Date: Wed, 8 Apr 2020 21:04:59 +0800 Subject: [PATCH] Update isSorted.md --- snippets/isSorted.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/isSorted.md b/snippets/isSorted.md index fc29d3810..cd0a6a7fe 100644 --- a/snippets/isSorted.md +++ b/snippets/isSorted.md @@ -14,7 +14,7 @@ const isSorted = arr => { let direction = -(arr[0] - arr[1]); for (let [i, val] of arr.entries()) { direction = !direction ? -(arr[i - 1] - arr[i]) : direction; - if (i === arr.length - 1) return !direction ? 0 : direction; + if (i === arr.length - 1) return !direction ? 0 : direction / Math.abs(direction); else if ((val - arr[i + 1]) * direction > 0) return 0; } }; @@ -24,4 +24,4 @@ const isSorted = arr => { isSorted([0, 1, 2, 2]); // 1 isSorted([4, 3, 2]); // -1 isSorted([4, 3, 5]); // 0 -``` \ No newline at end of file +```