mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
Fix/code smells (#1338)
* ♻️ refactor: improving and fixing some code * Updated Documentation in README.md * ♻️ refactor: improving isLeapYear * 🐛 chore: back changes * 🐛 fix: using reduce instead forEach * 🐛 fix: using reduce instead forEach * 🐛 fix: removing duplicated code * 🐛 chore: removing .js --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -5,9 +5,7 @@ describe('Test Graph2', () => {
|
||||
const graph = new Graph(vertices.length)
|
||||
|
||||
// adding vertices
|
||||
for (let i = 0; i < vertices.length; i++) {
|
||||
graph.addVertex(vertices[i])
|
||||
}
|
||||
vertices.forEach((vertice) => graph.addVertex(vertice))
|
||||
|
||||
// adding edges
|
||||
graph.addEdge('A', 'B')
|
||||
@ -27,7 +25,7 @@ describe('Test Graph2', () => {
|
||||
expect(mockFn.mock.calls.length).toBe(vertices.length)
|
||||
|
||||
// Collect adjacency lists from output (call args)
|
||||
const adjListArr = mockFn.mock.calls.map(v => v[0])
|
||||
const adjListArr = mockFn.mock.calls.map((v) => v[0])
|
||||
|
||||
expect(adjListArr).toEqual([
|
||||
'A -> B D E ',
|
||||
|
@ -47,8 +47,7 @@ class MinPriorityQueue {
|
||||
|
||||
// returns boolean value whether the heap is full or not
|
||||
isFull () {
|
||||
if (this.size === this.capacity) return true
|
||||
return false
|
||||
return this.size === this.capacity
|
||||
}
|
||||
|
||||
// prints the heap
|
||||
|
@ -106,8 +106,8 @@ Trie.prototype.contains = function (word) {
|
||||
// find the node with given prefix
|
||||
const node = this.findPrefix(word)
|
||||
// No such word exists
|
||||
if (node === null || node.count === 0) return false
|
||||
return true
|
||||
|
||||
return node !== null && node.count !== 0
|
||||
}
|
||||
|
||||
Trie.prototype.findOccurrences = function (word) {
|
||||
|
Reference in New Issue
Block a user