Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 875f6ca

Browse files
committed
fix: repo placement
1 parent a03369c commit 875f6ca

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

‎src/_Problems_/k-largest-in-array/index.js‎ renamed to ‎src/_DataStructures_/Heaps/k-largest-in-array/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const MaxHeap = require('../../_DataStructures_/Heaps/MaxHeap');
1+
const MaxHeap = require('../MaxHeap');
22

33
/**
44
* Find the 4 largest elements from an array
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Find 4 smallest elements in an array
3+
*/
4+
5+
const MinHeap = require('../MinHeap');
6+
7+
function findKSmallest(collection, k) {
8+
if (!collection || !Array.isArray(collection)) {
9+
throw new Error('Invalid / missing collection');
10+
}
11+
12+
// create a MinHeap using the collection
13+
const mh = new MinHeap(collection);
14+
const result = [];
15+
for (let i = 0; i < k; i += 1) {
16+
result.push(mh.getMin());
17+
}
18+
return result;
19+
}
20+
21+
module.exports = findKSmallest;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const MaxHeap = require('../MaxHeap');
2+
3+
/**
4+
* Find the 4 largest elements from an array
5+
*/
6+
7+
function findKLargest(collection, k) {
8+
if (!collection || !Array.isArray(collection)) {
9+
throw new Error('Invalid / missing collection');
10+
}
11+
12+
// create a MaxHeap using the collection
13+
const mh = new MaxHeap(collection);
14+
const result = [];
15+
16+
for (let i = 0; i < k; i += 1) {
17+
result.push(mh.getMax());
18+
}
19+
return result;
20+
}
21+
22+
module.exports = findKLargest;

‎src/_Problems_/k-smallest-in-array/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Find 4 smallest elements in an array
33
*/
44

5-
const MinHeap = require('../../_DataStructures_/Heaps/MinHeap');
5+
const MinHeap = require('../MinHeap');
66

77
function findKSmallest(collection, k) {
88
if (!collection || !Array.isArray(collection)) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /