Skip to content

Fix entire codebase #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 23, 2021
4 changes: 1 addition & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ jobs:
- name: npm install, build, and test
run: |
npm install doctest standard --save-dev
npx doctest **/*.js || true # TODO: error: Line 1: Unexpected token >>
npx doctest **/*.js || true # TODO: Add all doctests
npx standard
npm ci
npm run build --if-present
# TODO: Remove the next line when #539 is fixed.
rm Linear-Algebra/test/test.js String/LevenshteinDistance.test.js
npm test
env:
CI: true
2 changes: 1 addition & 1 deletion Conversions/DecimalToBinary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function decimalToBinary (num) {
var bin = []
const bin = []
while (num > 0) {
bin.unshift(num % 2)
num >>= 1 // basically /= 2 without remainder if any
Expand Down
8 changes: 4 additions & 4 deletions Conversions/HexToRGB.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function hexStringToRGB (hexString) {
var r = hexString.substring(0, 2)
var g = hexString.substring(2, 4)
var b = hexString.substring(4, 6)
let r = hexString.substring(0, 2)
let g = hexString.substring(2, 4)
let b = hexString.substring(4, 6)

r = parseInt(r, 16)
g = parseInt(g, 16)
b = parseInt(b, 16)
var obj = { r, g, b }
const obj = { r, g, b }

return obj
}
Expand Down
2 changes: 1 addition & 1 deletion Conversions/RomanToDecimal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var values = {
const values = {
I: 1,
V: 5,
X: 10,
Expand Down
40 changes: 20 additions & 20 deletions Data-Structures/Linked-List/SinglyLinkList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// class LinkedList and constructor
// Creates a LinkedList
var LinkedList = (function () {
const LinkedList = (function () {
function LinkedList () {
// Length of linklist and head is null at start
this.length = 0
Expand All @@ -19,7 +19,7 @@ var LinkedList = (function () {

// class node (constructor)
// Creating Node with element's value
var Node = (function () {
const Node = (function () {
function Node (element) {
this.element = element
this.next = null
Expand All @@ -39,12 +39,12 @@ var LinkedList = (function () {

// Creates a node and adds it to linklist
LinkedList.prototype.add = function (element) {
var node = new Node(element)
const node = new Node(element)
// Check if its the first element
if (this.head === null) {
this.head = node
} else {
var currentNode = this.head
let currentNode = this.head

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

// Removes the node with the value as param
LinkedList.prototype.remove = function (element) {
var currentNode = this.head
var previousNode
let currentNode = this.head
let previousNode

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

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

while (currentNode) {
index++
Expand All @@ -106,8 +106,8 @@ var LinkedList = (function () {

// Returns the element at an index
LinkedList.prototype.elementAt = function (index) {
var currentNode = this.head
var count = 0
let currentNode = this.head
let count = 0
while (count < index) {
count++
currentNode = currentNode.next
Expand All @@ -118,11 +118,11 @@ var LinkedList = (function () {
// Adds the element at specified index
LinkedList.prototype.addAt = function (index, element) {
index--
var node = new Node(element)
const node = new Node(element)

var currentNode = this.head
var previousNode
var currentIndex = 0
let currentNode = this.head
let previousNode
let currentIndex = 0

// Check if index is out of bounds of list
if (index > this.length) {
Expand Down Expand Up @@ -153,9 +153,9 @@ var LinkedList = (function () {
// Removes the node at specified index
LinkedList.prototype.removeAt = function (index) {
index--
var currentNode = this.head
var previousNode
var currentIndex = 0
let currentNode = this.head
let previousNode
let currentIndex = 0

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

// Function to view the LinkedList
LinkedList.prototype.view = function () {
var currentNode = this.head
var count = 0
let currentNode = this.head
let count = 0
while (count < this.length) {
count++
console.log(currentNode.element)
Expand All @@ -195,7 +195,7 @@ var LinkedList = (function () {
}())

// Implementation of LinkedList
var linklist = new LinkedList()
const linklist = new LinkedList()
linklist.add(2)
linklist.add(5)
linklist.add(8)
Expand Down
8 changes: 4 additions & 4 deletions Data-Structures/Stack/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Functions: push, pop, peek, view, length

// Creates a stack constructor
var Stack = (function () {
const Stack = (function () {
function Stack () {
// The top of the Stack
this.top = 0
Expand All @@ -29,7 +29,7 @@ var Stack = (function () {
}

this.top--
var result = this.stack[this.top]
const result = this.stack[this.top]
this.stack = this.stack.splice(0, this.top)
return result
}
Expand All @@ -46,14 +46,14 @@ var Stack = (function () {

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

return Stack
}())

// Implementation
var myStack = new Stack()
const myStack = new Stack()

myStack.push(1)
myStack.push(5)
Expand Down
6 changes: 3 additions & 3 deletions Data-Structures/Tree/BinarySearchTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

// class Node
var Node = (function () {
const Node = (function () {
// Node in the tree
function Node (val) {
this.value = val
Expand Down Expand Up @@ -67,7 +67,7 @@ var Node = (function () {
}())

// class Tree
var Tree = (function () {
const Tree = (function () {
function Tree () {
// Just store the root
this.root = null
Expand Down Expand Up @@ -103,7 +103,7 @@ var Tree = (function () {
}())

// Implementation of BST
var bst = new Tree()
const bst = new Tree()
bst.addValue(6)
bst.addValue(3)
bst.addValue(9)
Expand Down
32 changes: 16 additions & 16 deletions Data-Structures/Tree/Trie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var TrieNode = function TrieNode (key, parent) {
const TrieNode = function TrieNode (key, parent) {
this.key = key
this.count = 0
this.children = Object.create(null)
Expand All @@ -20,7 +20,7 @@ Trie.findAllWords = function (root, word, output) {
if (root.count > 0) {
if (typeof output === 'object') { output.push({ word: word, count: root.count }) }
}
var key
let key
for (key in root.children) {
word += key
this.findAllWords(root.children[key], word, output)
Expand All @@ -34,9 +34,9 @@ Trie.prototype.insert = function (word) {
this.root.count += 1
return
}
var node = this.root
var len = word.length
var i
let node = this.root
const len = word.length
let i
for (i = 0; i < len; i++) {
if (node.children[word.charAt(i)] === undefined) { node.children[word.charAt(i)] = new TrieNode(word.charAt(i), node) }
node = node.children[word.charAt(i)]
Expand All @@ -46,9 +46,9 @@ Trie.prototype.insert = function (word) {

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

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

Trie.prototype.findAllWords = function (prefix) {
var output = []
const output = []
// find the node with provided prefix
var node = this.findPrefix(prefix)
const node = this.findPrefix(prefix)
// No such prefix exists
if (node === null) return output
Trie.findAllWords(node, prefix, output)
Expand All @@ -104,23 +104,23 @@ Trie.prototype.findAllWords = function (prefix) {

Trie.prototype.contains = function (word) {
// find the node with given prefix
var node = this.findPrefix(word)
const node = this.findPrefix(word)
// No such word exists
if (node === null || node.count === 0) return false
return true
}

Trie.prototype.findOccurences = function (word) {
// find the node with given prefix
var node = this.findPrefix(word)
const node = this.findPrefix(word)
// No such word exists
if (node === null) return 0
return node.count
};

// To test
(function demo () {
var x = new Trie()
const x = new Trie()
x.insert('sheldon')
x.insert('hello')
x.insert('anyword')
Expand Down
7 changes: 3 additions & 4 deletions Dynamic-Programming/ZeroOneKnapsack.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ const main = () => {
arr.push(input[j])
j++
}
const newArr = []
arr.map(e => {
newArr.push(e.trim().split(' ').map(Number))
})
const newArr = arr.map(e =>
e.trim().split(' ').map(Number)
)
const cache = []
for (let i = 0; i <= currlen; i++) {
const temp = []
Expand Down
Loading