Skip to content

Commit 4ce3dbe

Browse files
defaudegithub-actions
and
github-actions
authored
dependencies: update and clean (and auto-fix style issues) (#1195)
* Update npm dependencies (and auto-fix style issues) * Updated Documentation in README.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 18baef8 commit 4ce3dbe

File tree

5 files changed

+7318
-12314
lines changed

5 files changed

+7318
-12314
lines changed

Diff for: Cache/LFUCache.js

+121-121
Original file line numberDiff line numberDiff line change
@@ -45,210 +45,210 @@ class FrequencyMap extends Map {
4545
}
4646

4747
class LFUCache {
48-
#capacity
49-
#frequencyMap
48+
#capacity
49+
#frequencyMap
5050

51-
/**
51+
/**
5252
* @param {number} capacity - The range of LFUCache
5353
* @returns {LFUCache} - sealed
5454
*/
55-
constructor (capacity) {
56-
this.#capacity = capacity
57-
this.#frequencyMap = new FrequencyMap()
58-
this.misses = 0
59-
this.hits = 0
60-
this.cache = new Map()
61-
62-
return Object.seal(this)
63-
}
55+
constructor (capacity) {
56+
this.#capacity = capacity
57+
this.#frequencyMap = new FrequencyMap()
58+
this.misses = 0
59+
this.hits = 0
60+
this.cache = new Map()
61+
62+
return Object.seal(this)
63+
}
6464

65-
/**
65+
/**
6666
* Get the capacity of the LFUCache
6767
* @returns {number}
6868
*/
69-
get capacity () {
70-
return this.#capacity
71-
}
69+
get capacity () {
70+
return this.#capacity
71+
}
7272

73-
/**
73+
/**
7474
* Get the current size of LFUCache
7575
* @returns {number}
7676
*/
77-
get size () {
78-
return this.cache.size
79-
}
77+
get size () {
78+
return this.cache.size
79+
}
8080

81-
/**
81+
/**
8282
* Set the capacity of the LFUCache if you decrease the capacity its removed CacheNodes following the LFU - least frequency used
8383
*/
84-
set capacity (newCapacity) {
85-
if (this.#capacity > newCapacity) {
86-
let diff = this.#capacity - newCapacity // get the decrement number of capacity
84+
set capacity (newCapacity) {
85+
if (this.#capacity > newCapacity) {
86+
let diff = this.#capacity - newCapacity // get the decrement number of capacity
8787

88-
while (diff--) {
89-
this.#removeCacheNode()
90-
}
91-
92-
this.cache.size === 0 && this.#frequencyMap.clear()
88+
while (diff--) {
89+
this.#removeCacheNode()
9390
}
9491

95-
this.#capacity = newCapacity
92+
this.cache.size === 0 && this.#frequencyMap.clear()
9693
}
9794

98-
get info () {
99-
return Object.freeze({
100-
misses: this.misses,
101-
hits: this.hits,
102-
capacity: this.capacity,
103-
currentSize: this.size,
104-
leastFrequency: this.leastFrequency
105-
})
106-
}
95+
this.#capacity = newCapacity
96+
}
10797

108-
get leastFrequency () {
109-
const freqCacheIterator = this.#frequencyMap.keys()
110-
let leastFrequency = freqCacheIterator.next().value || null
98+
get info () {
99+
return Object.freeze({
100+
misses: this.misses,
101+
hits: this.hits,
102+
capacity: this.capacity,
103+
currentSize: this.size,
104+
leastFrequency: this.leastFrequency
105+
})
106+
}
111107

112-
// select the non-empty frequency Set
113-
while (this.#frequencyMap.get(leastFrequency)?.size === 0) {
114-
leastFrequency = freqCacheIterator.next().value
115-
}
108+
get leastFrequency () {
109+
const freqCacheIterator = this.#frequencyMap.keys()
110+
let leastFrequency = freqCacheIterator.next().value || null
116111

117-
return leastFrequency
112+
// select the non-empty frequency Set
113+
while (this.#frequencyMap.get(leastFrequency)?.size === 0) {
114+
leastFrequency = freqCacheIterator.next().value
118115
}
119116

120-
#removeCacheNode () {
121-
const leastFreqSet = this.#frequencyMap.get(this.leastFrequency)
122-
// Select the least recently used node from the least Frequency set
123-
const LFUNode = leastFreqSet.values().next().value
117+
return leastFrequency
118+
}
124119

125-
leastFreqSet.delete(LFUNode)
126-
this.cache.delete(LFUNode.key)
127-
}
120+
#removeCacheNode () {
121+
const leastFreqSet = this.#frequencyMap.get(this.leastFrequency)
122+
// Select the least recently used node from the least Frequency set
123+
const LFUNode = leastFreqSet.values().next().value
124+
125+
leastFreqSet.delete(LFUNode)
126+
this.cache.delete(LFUNode.key)
127+
}
128128

129-
/**
129+
/**
130130
* if key exist then return true otherwise false
131131
* @param {any} key
132132
* @returns {boolean}
133133
*/
134-
has (key) {
135-
key = String(key) // converted to string
134+
has (key) {
135+
key = String(key) // converted to string
136136

137-
return this.cache.has(key)
138-
}
137+
return this.cache.has(key)
138+
}
139139

140-
/**
140+
/**
141141
* @method get
142142
* @description - This method return the value of key & refresh the frequencyMap by the oldNode
143143
* @param {string} key
144144
* @returns {any}
145145
*/
146-
get (key) {
147-
key = String(key) // converted to string
146+
get (key) {
147+
key = String(key) // converted to string
148148

149-
if (this.cache.has(key)) {
150-
const oldNode = this.cache.get(key)
151-
this.#frequencyMap.refresh(oldNode)
149+
if (this.cache.has(key)) {
150+
const oldNode = this.cache.get(key)
151+
this.#frequencyMap.refresh(oldNode)
152152

153-
this.hits++
153+
this.hits++
154154

155-
return oldNode.value
156-
}
157-
158-
this.misses++
159-
return null
155+
return oldNode.value
160156
}
161157

162-
/**
158+
this.misses++
159+
return null
160+
}
161+
162+
/**
163163
* @method set
164164
* @description - This method stored the value by key & add frequency if it doesn't exist
165165
* @param {string} key
166166
* @param {any} value
167167
* @param {number} frequency
168168
* @returns {LFUCache}
169169
*/
170-
set (key, value, frequency = 1) {
171-
key = String(key) // converted to string
170+
set (key, value, frequency = 1) {
171+
key = String(key) // converted to string
172172

173-
if (this.#capacity === 0) {
174-
throw new RangeError('LFUCache ERROR: The Capacity is 0')
175-
}
173+
if (this.#capacity === 0) {
174+
throw new RangeError('LFUCache ERROR: The Capacity is 0')
175+
}
176176

177-
if (this.cache.has(key)) {
178-
const node = this.cache.get(key)
179-
node.value = value
177+
if (this.cache.has(key)) {
178+
const node = this.cache.get(key)
179+
node.value = value
180180

181-
this.#frequencyMap.refresh(node)
181+
this.#frequencyMap.refresh(node)
182182

183-
return this
184-
}
183+
return this
184+
}
185185

186-
// if the cache size is full, then it's delete the Least Frequency Used node
187-
if (this.#capacity === this.cache.size) {
188-
this.#removeCacheNode()
189-
}
186+
// if the cache size is full, then it's delete the Least Frequency Used node
187+
if (this.#capacity === this.cache.size) {
188+
this.#removeCacheNode()
189+
}
190190

191-
const newNode = new CacheNode(key, value, frequency)
191+
const newNode = new CacheNode(key, value, frequency)
192192

193-
this.cache.set(key, newNode)
194-
this.#frequencyMap.insert(newNode)
193+
this.cache.set(key, newNode)
194+
this.#frequencyMap.insert(newNode)
195195

196-
return this
197-
}
196+
return this
197+
}
198198

199-
/**
199+
/**
200200
* @method parse
201201
* @description - This method receive a valid LFUCache JSON & run JSON.prase() method and merge with existing LFUCache
202202
* @param {JSON} json
203203
* @returns {LFUCache} - merged
204204
*/
205-
parse (json) {
206-
const { misses, hits, cache } = JSON.parse(json)
205+
parse (json) {
206+
const { misses, hits, cache } = JSON.parse(json)
207207

208-
this.misses += misses ?? 0
209-
this.hits += hits ?? 0
208+
this.misses += misses ?? 0
209+
this.hits += hits ?? 0
210210

211-
for (const key in cache) {
212-
const { value, frequency } = cache[key]
213-
this.set(key, value, frequency)
214-
}
215-
216-
return this
211+
for (const key in cache) {
212+
const { value, frequency } = cache[key]
213+
this.set(key, value, frequency)
217214
}
218215

219-
/**
216+
return this
217+
}
218+
219+
/**
220220
* @method clear
221221
* @description - This method cleared the whole LFUCache
222222
* @returns {LFUCache}
223223
*/
224-
clear () {
225-
this.cache.clear()
226-
this.#frequencyMap.clear()
224+
clear () {
225+
this.cache.clear()
226+
this.#frequencyMap.clear()
227227

228-
return this
229-
}
228+
return this
229+
}
230230

231-
/**
231+
/**
232232
* @method toString
233233
* @description - This method generate a JSON format of LFUCache & return it.
234234
* @param {number} indent
235235
* @returns {string} - JSON
236236
*/
237-
toString (indent) {
238-
const replacer = (_, value) => {
239-
if (value instanceof Set) {
240-
return [...value]
241-
}
242-
243-
if (value instanceof Map) {
244-
return Object.fromEntries(value)
245-
}
237+
toString (indent) {
238+
const replacer = (_, value) => {
239+
if (value instanceof Set) {
240+
return [...value]
241+
}
246242

247-
return value
243+
if (value instanceof Map) {
244+
return Object.fromEntries(value)
248245
}
249246

250-
return JSON.stringify(this, replacer, indent)
247+
return value
251248
}
249+
250+
return JSON.stringify(this, replacer, indent)
251+
}
252252
}
253253

254254
export default LFUCache

Diff for: DIRECTORY.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* [AllCombinationsOfSizeK](Backtracking/AllCombinationsOfSizeK.js)
33
* [GeneratePermutations](Backtracking/GeneratePermutations.js)
44
* [KnightTour](Backtracking/KnightTour.js)
5-
* [NQueen](Backtracking/NQueen.js)
5+
* [NQueens](Backtracking/NQueens.js)
66
* [RatInAMaze](Backtracking/RatInAMaze.js)
77
* [Sudoku](Backtracking/Sudoku.js)
88
* [SumOfSubset](Backtracking/SumOfSubset.js)
@@ -149,6 +149,7 @@
149149
* [CollatzSequence](Maths/CollatzSequence.js)
150150
* [Coordinate](Maths/Coordinate.js)
151151
* [CoPrimeCheck](Maths/CoPrimeCheck.js)
152+
* [CountNumbersDivisible](Maths/CountNumbersDivisible.js)
152153
* [DecimalExpansion](Maths/DecimalExpansion.js)
153154
* [DecimalIsolate](Maths/DecimalIsolate.js)
154155
* [DegreeToRadian](Maths/DegreeToRadian.js)
@@ -172,6 +173,7 @@
172173
* [IsDivisible](Maths/IsDivisible.js)
173174
* [IsEven](Maths/IsEven.js)
174175
* [IsOdd](Maths/IsOdd.js)
176+
* [isPalindromeIntegerNumber](Maths/isPalindromeIntegerNumber.js)
175177
* [IsPronic](Maths/IsPronic.js)
176178
* [IsSquareFree](Maths/IsSquareFree.js)
177179
* [JugglerSequence](Maths/JugglerSequence.js)
@@ -227,6 +229,7 @@
227229
* [Problem008](Project-Euler/Problem008.js)
228230
* [Problem009](Project-Euler/Problem009.js)
229231
* [Problem010](Project-Euler/Problem010.js)
232+
* [Problem011](Project-Euler/Problem011.js)
230233
* [Problem012](Project-Euler/Problem012.js)
231234
* [Problem013](Project-Euler/Problem013.js)
232235
* [Problem014](Project-Euler/Problem014.js)
@@ -237,6 +240,7 @@
237240
* [Problem020](Project-Euler/Problem020.js)
238241
* [Problem023](Project-Euler/Problem023.js)
239242
* [Problem025](Project-Euler/Problem025.js)
243+
* [Problem044](Project-Euler/Problem044.js)
240244
* **Recursive**
241245
* [BinaryEquivalent](Recursive/BinaryEquivalent.js)
242246
* [BinarySearch](Recursive/BinarySearch.js)
@@ -290,6 +294,7 @@
290294
* [ShellSort](Sorts/ShellSort.js)
291295
* [SimplifiedWiggleSort](Sorts/SimplifiedWiggleSort.js)
292296
* [StoogeSort](Sorts/StoogeSort.js)
297+
* [SwapSort](Sorts/SwapSort.js)
293298
* [TimSort](Sorts/TimSort.js)
294299
* [TopologicalSort](Sorts/TopologicalSort.js)
295300
* **String**

Diff for: Maths/CollatzSequence.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export function collatz (n) {
2626
steps.push(n)
2727
}
2828

29-
return { result: n, steps: steps }
29+
return { result: n, steps }
3030
}

0 commit comments

Comments
 (0)