-
-
Notifications
You must be signed in to change notification settings - Fork 26
Homework tasks #2
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🥇
JavaScript/8-timer.js
Outdated
@@ -0,0 +1,47 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8-timeout.js
JavaScript/8-timer.js
Outdated
|
||
const setTimer = msec => { | ||
timer = setTimeout(() => { | ||
console.log('Cache cleaned'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicate code
JavaScript/8-timer.js
Outdated
}, msec); | ||
}; | ||
|
||
const generateKey = (...args) => args.join('|'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add types to cache key
JavaScript/8-timer.js
Outdated
|
||
return (...args) => { | ||
if (!timer) setTimer(msec); | ||
const key = generateKey(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass array to generateKey
to avoid arguments repack
JavaScript/8-timer.js
Outdated
|
||
console.log(`Calculate: ${args} = ${fn(...args)}`); | ||
const res = fn(...args); | ||
cache[key] = res; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not write undefined to cache
JavaScript/8-timer.js
Outdated
if (!timer) setTimer(msec); | ||
const key = generateKey(...args); | ||
|
||
if (cache[key]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check type, aware of 0
, false
and empty string
const length = size.length; | ||
const data = parseFloat(size, 10); | ||
let k = 1; | ||
switch (size.charAt(length - 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use new Map
or {}
for large cases
JavaScript/a-bytes.js
Outdated
let bytes = 0; | ||
for (const i in obj) { | ||
switch (typeof obj[i]) { | ||
case 'number': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
number: 8,
boolean: 4
....
}
JavaScript/a-bytes.js
Outdated
|
||
console.log(`Calculating: ${key}`); | ||
cache[key] = fn(...args); | ||
console.dir(`Cache size: ${getSize(cache)}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculate getSize(cache)
once
Problems solved. @tshemsedinov review, please. |
No description provided.