From 9b572cc7b66572d16f7cbbbc89abb93cd9d78cc5 Mon Sep 17 00:00:00 2001 From: tcmal Date: Mon, 12 Mar 2018 19:36:47 +0000 Subject: [PATCH 1/3] Fix incorrect test for sortedLastIndex snippet --- snippets/sortedLastIndex.md | 2 +- test/sortedLastIndex/sortedLastIndex.js | 2 +- test/sortedLastIndex/sortedLastIndex.test.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/sortedLastIndex.md b/snippets/sortedLastIndex.md index 43ecefab5..88ba341e1 100644 --- a/snippets/sortedLastIndex.md +++ b/snippets/sortedLastIndex.md @@ -9,7 +9,7 @@ Use `Array.reverse()` and `Array.findIndex()` to find the appropriate last index const sortedLastIndex = (arr, n) => { const isDescending = arr[0] > arr[arr.length - 1]; const index = arr.reverse().findIndex(el => (isDescending ? n <= el : n >= el)); - return index === -1 ? 0 : arr.length - index - 1; + return index === -1 ? 0 : arr.length - index; }; ``` diff --git a/test/sortedLastIndex/sortedLastIndex.js b/test/sortedLastIndex/sortedLastIndex.js index 1fc2a6416..b883fee5f 100644 --- a/test/sortedLastIndex/sortedLastIndex.js +++ b/test/sortedLastIndex/sortedLastIndex.js @@ -1,6 +1,6 @@ const sortedLastIndex = (arr, n) => { const isDescending = arr[0] > arr[arr.length - 1]; const index = arr.reverse().findIndex(el => (isDescending ? n <= el : n >= el)); -return index === -1 ? 0 : arr.length - index - 1; +return index === -1 ? 0 : arr.length - index; }; module.exports = sortedLastIndex; \ No newline at end of file diff --git a/test/sortedLastIndex/sortedLastIndex.test.js b/test/sortedLastIndex/sortedLastIndex.test.js index cdb77d095..df333dfdb 100644 --- a/test/sortedLastIndex/sortedLastIndex.test.js +++ b/test/sortedLastIndex/sortedLastIndex.test.js @@ -5,8 +5,8 @@ test('Testing sortedLastIndex', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof sortedLastIndex === 'function', 'sortedLastIndex is a Function'); - t.equal(sortedLastIndex([10, 20, 30, 30, 40], 30), 3, 'Returns the highest index to insert the element without messing up the list order'); - //t.deepEqual(sortedLastIndex(args..), 'Expected'); + t.equal(sortedLastIndex([10, 20, 30, 30, 40], 30), 4, 'Returns the highest index to insert the element without messing up the list order'); + //t.deepEqual(sortedLastIndex(args..), 'Expected'); //t.equal(sortedLastIndex(args..), 'Expected'); //t.false(sortedLastIndex(args..), 'Expected'); //t.throws(sortedLastIndex(args..), 'Expected'); From a8350cebc39c4862e2a7a3777f9a4c1ca3e3d38f Mon Sep 17 00:00:00 2001 From: tcmal Date: Mon, 12 Mar 2018 19:38:17 +0000 Subject: [PATCH 2/3] Fixed bad formatting in sortedLastIndex test --- test/sortedLastIndex/sortedLastIndex.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sortedLastIndex/sortedLastIndex.test.js b/test/sortedLastIndex/sortedLastIndex.test.js index df333dfdb..a80ef11dc 100644 --- a/test/sortedLastIndex/sortedLastIndex.test.js +++ b/test/sortedLastIndex/sortedLastIndex.test.js @@ -6,7 +6,7 @@ test('Testing sortedLastIndex', (t) => { //Please go to https://github.com/substack/tape t.true(typeof sortedLastIndex === 'function', 'sortedLastIndex is a Function'); t.equal(sortedLastIndex([10, 20, 30, 30, 40], 30), 4, 'Returns the highest index to insert the element without messing up the list order'); - //t.deepEqual(sortedLastIndex(args..), 'Expected'); + //t.deepEqual(sortedLastIndex(args..), 'Expected'); //t.equal(sortedLastIndex(args..), 'Expected'); //t.false(sortedLastIndex(args..), 'Expected'); //t.throws(sortedLastIndex(args..), 'Expected'); From a3209c4289c998ddfb7b08ff05f5ea2063046395 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 12 Mar 2018 21:58:04 +0200 Subject: [PATCH 3/3] Update sortedLastIndex.md --- snippets/sortedLastIndex.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/sortedLastIndex.md b/snippets/sortedLastIndex.md index 88ba341e1..7f1a90bc7 100644 --- a/snippets/sortedLastIndex.md +++ b/snippets/sortedLastIndex.md @@ -14,5 +14,5 @@ const sortedLastIndex = (arr, n) => { ``` ```js -sortedLastIndex([10, 20, 30, 30, 40], 30); // 3 +sortedLastIndex([10, 20, 30, 30, 40], 30); // 4 ```