Skip to content

Commit 74a3be8

Browse files
authored
Merge pull request #609 from raklaptudirm/master
Fix entire codebase
2 parents d220eb9 + cf98ded commit 74a3be8

28 files changed

+204
-197
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ jobs:
1515
- name: npm install, build, and test
1616
run: |
1717
npm install doctest standard --save-dev
18-
npx doctest **/*.js || true # TODO: error: Line 1: Unexpected token >>
18+
npx doctest **/*.js || true # TODO: Add all doctests
1919
npx standard
2020
npm ci
2121
npm run build --if-present
22-
# TODO: Remove the next line when #539 is fixed.
23-
rm Linear-Algebra/test/test.js String/LevenshteinDistance.test.js
2422
npm test
2523
env:
2624
CI: true

Conversions/DecimalToBinary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function decimalToBinary (num) {
2-
var bin = []
2+
const bin = []
33
while (num > 0) {
44
bin.unshift(num % 2)
55
num >>= 1 // basically /= 2 without remainder if any

Conversions/HexToRGB.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function hexStringToRGB (hexString) {
2-
var r = hexString.substring(0, 2)
3-
var g = hexString.substring(2, 4)
4-
var b = hexString.substring(4, 6)
2+
let r = hexString.substring(0, 2)
3+
let g = hexString.substring(2, 4)
4+
let b = hexString.substring(4, 6)
55

66
r = parseInt(r, 16)
77
g = parseInt(g, 16)
88
b = parseInt(b, 16)
9-
var obj = { r, g, b }
9+
const obj = { r, g, b }
1010

1111
return obj
1212
}

Conversions/RomanToDecimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var values = {
1+
const values = {
22
I: 1,
33
V: 5,
44
X: 10,

Data-Structures/Linked-List/SinglyLinkList.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// class LinkedList and constructor
1212
// Creates a LinkedList
13-
var LinkedList = (function () {
13+
const LinkedList = (function () {
1414
function LinkedList () {
1515
// Length of linklist and head is null at start
1616
this.length = 0
@@ -19,7 +19,7 @@ var LinkedList = (function () {
1919

2020
// class node (constructor)
2121
// Creating Node with element's value
22-
var Node = (function () {
22+
const Node = (function () {
2323
function Node (element) {
2424
this.element = element
2525
this.next = null
@@ -39,12 +39,12 @@ var LinkedList = (function () {
3939

4040
// Creates a node and adds it to linklist
4141
LinkedList.prototype.add = function (element) {
42-
var node = new Node(element)
42+
const node = new Node(element)
4343
// Check if its the first element
4444
if (this.head === null) {
4545
this.head = node
4646
} else {
47-
var currentNode = this.head
47+
let currentNode = this.head
4848

4949
// Loop till there is node present in the list
5050
while (currentNode.next) {
@@ -60,8 +60,8 @@ var LinkedList = (function () {
6060

6161
// Removes the node with the value as param
6262
LinkedList.prototype.remove = function (element) {
63-
var currentNode = this.head
64-
var previousNode
63+
let currentNode = this.head
64+
let previousNode
6565

6666
// Check if the head node is the element to remove
6767
if (currentNode.element === element) {
@@ -88,8 +88,8 @@ var LinkedList = (function () {
8888

8989
// Returns the index of the element passed as param otherwise -1
9090
LinkedList.prototype.indexOf = function (element) {
91-
var currentNode = this.head
92-
var index = -1
91+
let currentNode = this.head
92+
let index = -1
9393

9494
while (currentNode) {
9595
index++
@@ -106,8 +106,8 @@ var LinkedList = (function () {
106106

107107
// Returns the element at an index
108108
LinkedList.prototype.elementAt = function (index) {
109-
var currentNode = this.head
110-
var count = 0
109+
let currentNode = this.head
110+
let count = 0
111111
while (count < index) {
112112
count++
113113
currentNode = currentNode.next
@@ -118,11 +118,11 @@ var LinkedList = (function () {
118118
// Adds the element at specified index
119119
LinkedList.prototype.addAt = function (index, element) {
120120
index--
121-
var node = new Node(element)
121+
const node = new Node(element)
122122

123-
var currentNode = this.head
124-
var previousNode
125-
var currentIndex = 0
123+
let currentNode = this.head
124+
let previousNode
125+
let currentIndex = 0
126126

127127
// Check if index is out of bounds of list
128128
if (index > this.length) {
@@ -153,9 +153,9 @@ var LinkedList = (function () {
153153
// Removes the node at specified index
154154
LinkedList.prototype.removeAt = function (index) {
155155
index--
156-
var currentNode = this.head
157-
var previousNode
158-
var currentIndex = 0
156+
let currentNode = this.head
157+
let previousNode
158+
let currentIndex = 0
159159

160160
// Check if index is present in list
161161
if (index < 0 || index >= this.length) {
@@ -181,8 +181,8 @@ var LinkedList = (function () {
181181

182182
// Function to view the LinkedList
183183
LinkedList.prototype.view = function () {
184-
var currentNode = this.head
185-
var count = 0
184+
let currentNode = this.head
185+
let count = 0
186186
while (count < this.length) {
187187
count++
188188
console.log(currentNode.element)
@@ -195,7 +195,7 @@ var LinkedList = (function () {
195195
}())
196196

197197
// Implementation of LinkedList
198-
var linklist = new LinkedList()
198+
const linklist = new LinkedList()
199199
linklist.add(2)
200200
linklist.add(5)
201201
linklist.add(8)

Data-Structures/Stack/Stack.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Functions: push, pop, peek, view, length
99

1010
// Creates a stack constructor
11-
var Stack = (function () {
11+
const Stack = (function () {
1212
function Stack () {
1313
// The top of the Stack
1414
this.top = 0
@@ -29,7 +29,7 @@ var Stack = (function () {
2929
}
3030

3131
this.top--
32-
var result = this.stack[this.top]
32+
const result = this.stack[this.top]
3333
this.stack = this.stack.splice(0, this.top)
3434
return result
3535
}
@@ -46,14 +46,14 @@ var Stack = (function () {
4646

4747
// To see all the elements in the stack
4848
Stack.prototype.view = function () {
49-
for (var i = 0; i < this.top; i++) { console.log(this.stack[i]) }
49+
for (let i = 0; i < this.top; i++) { console.log(this.stack[i]) }
5050
}
5151

5252
return Stack
5353
}())
5454

5555
// Implementation
56-
var myStack = new Stack()
56+
const myStack = new Stack()
5757

5858
myStack.push(1)
5959
myStack.push(5)

Data-Structures/Tree/BinarySearchTree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// class Node
14-
var Node = (function () {
14+
const Node = (function () {
1515
// Node in the tree
1616
function Node (val) {
1717
this.value = val
@@ -67,7 +67,7 @@ var Node = (function () {
6767
}())
6868

6969
// class Tree
70-
var Tree = (function () {
70+
const Tree = (function () {
7171
function Tree () {
7272
// Just store the root
7373
this.root = null
@@ -103,7 +103,7 @@ var Tree = (function () {
103103
}())
104104

105105
// Implementation of BST
106-
var bst = new Tree()
106+
const bst = new Tree()
107107
bst.addValue(6)
108108
bst.addValue(3)
109109
bst.addValue(9)

Data-Structures/Tree/Trie.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var TrieNode = function TrieNode (key, parent) {
1+
const TrieNode = function TrieNode (key, parent) {
22
this.key = key
33
this.count = 0
44
this.children = Object.create(null)
@@ -20,7 +20,7 @@ Trie.findAllWords = function (root, word, output) {
2020
if (root.count > 0) {
2121
if (typeof output === 'object') { output.push({ word: word, count: root.count }) }
2222
}
23-
var key
23+
let key
2424
for (key in root.children) {
2525
word += key
2626
this.findAllWords(root.children[key], word, output)
@@ -34,9 +34,9 @@ Trie.prototype.insert = function (word) {
3434
this.root.count += 1
3535
return
3636
}
37-
var node = this.root
38-
var len = word.length
39-
var i
37+
let node = this.root
38+
const len = word.length
39+
let i
4040
for (i = 0; i < len; i++) {
4141
if (node.children[word.charAt(i)] === undefined) { node.children[word.charAt(i)] = new TrieNode(word.charAt(i), node) }
4242
node = node.children[word.charAt(i)]
@@ -46,9 +46,9 @@ Trie.prototype.insert = function (word) {
4646

4747
Trie.prototype.findPrefix = function (word) {
4848
if (typeof word !== 'string') return null
49-
var node = this.root
50-
var len = word.length
51-
var i
49+
let node = this.root
50+
const len = word.length
51+
let i
5252
// After end of this loop node will be at desired prefix
5353
for (i = 0; i < len; i++) {
5454
if (node.children[word.charAt(i)] === undefined) return null // No such prefix exists
@@ -69,9 +69,9 @@ Trie.prototype.remove = function (word, count) {
6969
return
7070
}
7171

72-
var child = this.root
73-
var len = word.length
74-
var i, key
72+
let child = this.root
73+
const len = word.length
74+
let i, key
7575
// child: node which is to be deleted
7676
for (i = 0; i < len; i++) {
7777
key = word.charAt(i)
@@ -93,9 +93,9 @@ Trie.prototype.remove = function (word, count) {
9393
}
9494

9595
Trie.prototype.findAllWords = function (prefix) {
96-
var output = []
96+
const output = []
9797
// find the node with provided prefix
98-
var node = this.findPrefix(prefix)
98+
const node = this.findPrefix(prefix)
9999
// No such prefix exists
100100
if (node === null) return output
101101
Trie.findAllWords(node, prefix, output)
@@ -104,23 +104,23 @@ Trie.prototype.findAllWords = function (prefix) {
104104

105105
Trie.prototype.contains = function (word) {
106106
// find the node with given prefix
107-
var node = this.findPrefix(word)
107+
const node = this.findPrefix(word)
108108
// No such word exists
109109
if (node === null || node.count === 0) return false
110110
return true
111111
}
112112

113113
Trie.prototype.findOccurences = function (word) {
114114
// find the node with given prefix
115-
var node = this.findPrefix(word)
115+
const node = this.findPrefix(word)
116116
// No such word exists
117117
if (node === null) return 0
118118
return node.count
119119
};
120120

121121
// To test
122122
(function demo () {
123-
var x = new Trie()
123+
const x = new Trie()
124124
x.insert('sheldon')
125125
x.insert('hello')
126126
x.insert('anyword')

Dynamic-Programming/ZeroOneKnapsack.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ const main = () => {
5050
arr.push(input[j])
5151
j++
5252
}
53-
const newArr = []
54-
arr.map(e => {
55-
newArr.push(e.trim().split(' ').map(Number))
56-
})
53+
const newArr = arr.map(e =>
54+
e.trim().split(' ').map(Number)
55+
)
5756
const cache = []
5857
for (let i = 0; i <= currlen; i++) {
5958
const temp = []

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy