• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knaxus / problem-solving-javascript / #562

18 Jun 2023 05:07PM UTC coverage: 97.602%. First build
#562

push

travis-ci

web-flow
Merge pull request #207 from Ahtaxam/master

Add 3-sum problem with improvement issue #208

525 of 541 branches covered (97.04%)

Branch coverage included in aggregate %.

21 of 21 new or added lines in 1 file covered. (100.0%)

1266 of 1294 relevant lines covered (97.84%)

32.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/_DataStructures_/Trees/BinarySearchTree/index.js
1
const Node = require('./Node');
3✔
2
const BSTUtils = require('./utils');
3✔
3

4
class BinarySearchTree {
5
  constructor(value) {
6
    if (!value) throw new Error('Root node value required');
18!
7
    this.root = new Node(value);
18✔
8
  }
9

10
  isEmpty() {
11
    return this.root === null;
2✔
12
  }
13

14
  /** Layered methods to simplify the BST API using utils under the hood  */
15

16
  add(value) {
17
    return BSTUtils.insert(this.root, value);
95✔
18
  }
19

20
  preorder() {
21
    return BSTUtils.preorder(this.root, []);
3✔
22
  }
23

24
  postorder() {
25
    return BSTUtils.postorder(this.root, []);
3✔
26
  }
27

28
  inorder() {
29
    return BSTUtils.inorder(this.root, []);
5✔
30
  }
31

32
  search(value) {
33
    return BSTUtils.search(this.root, value);
2✔
34
  }
35

36
  getMinimum() {
37
    const minNode = BSTUtils.findMinNode(this.root);
2✔
38
    return minNode.value;
2✔
39
  }
40

41
  getMaximum() {
42
    const maxNode = BSTUtils.findMaxNode(this.root);
2✔
43
    return maxNode.value;
2✔
44
  }
45

46
  remove(value) {
47
    this.root = BSTUtils.delete(this.root, value);
16✔
48
  }
49
}
50

51
// const bst = new BinarySearchTree(6);
52
// [4, 9, 2, 5, 8, 12].forEach(el => bst.add(el));
53

54
// const preorder = bst.preorder();
55
// console.log('Preorder Traversal - ', preorder);
56

57
// const inorder = bst.inorder();
58
// console.log('Inorder Traversal - ', inorder);
59

60
// const postorder = bst.postorder();
61
// console.log('Postorder Traversal - ', postorder);
62

63
// const search = 18;
64
// console.log(`Search for ${search}`, bst.search(search));
65

66
// const minNode = bst.getMinimum();
67
// console.log('Minimum value =>', minNode);
68

69
// const maxNode = bst.getMaximum();
70
// console.log('Maximum value =>', maxNode);
71

72
// bst.remove(4);
73
// console.log(bst.preorder());
74

75
// console.log(bst.root);
76

77
module.exports = BinarySearchTree;
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc