From cde6e8a2291bb97e08b28dedf093942e664eaa09 Mon Sep 17 00:00:00 2001 From: Balaji Saravanan Date: Sun, 29 May 2022 12:01:08 +0530 Subject: [PATCH 1/2] Update heap.js Fix proper parent index fetching --- src/data-structures/heaps/heap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data-structures/heaps/heap.js b/src/data-structures/heaps/heap.js index 54863c39..537894ee 100644 --- a/src/data-structures/heaps/heap.js +++ b/src/data-structures/heaps/heap.js @@ -59,7 +59,7 @@ class Heap { */ bubbleUp() { let index = this.size - 1; - const parent = (i) => Math.ceil(i / 2 - 1); + const parent = (i) => Math.ceil(i / 2) - 1; while (parent(index) >= 0 && this.comparator(parent(index), index) > 0) { this.swap(parent(index), index); index = parent(index); From fefb06a6b51a7699cb3986ed2d20dc0d03511055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ca=C3=ADque=20de=20Castro=20Soares=20da=20Silva?= Date: Mon, 26 Dec 2022 17:45:05 -0300 Subject: [PATCH 2/2] Fix return of unshift method Fix return of unshift method --- book/content/part02/array.asc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/content/part02/array.asc b/book/content/part02/array.asc index 3bde2929..25c029ee 100644 --- a/book/content/part02/array.asc +++ b/book/content/part02/array.asc @@ -73,7 +73,7 @@ Here's an example: [source, javascript] ---- const array = [2, 5, 1]; -array.unshift(0); // ↪️ 8 +array.unshift(0); // ↪️ 4 console.log(array); // [ 0, 2, 5, 1 ] array.unshift(-2, -1); // ↪️ 6 console.log(array); // [ -2, -1, 0, 2, 5, 1 ]