Repository

## 30-seconds/30-seconds-of-code

Short JavaScript code snippets for all your development needs
107115 10526 2606 277
Issue

## addDaysToDate fails with non-UTC timezone

• 000
addDaysToDate('2021-10-2', 10) (residing in +5:30 timezone) gives output '2021-10-11'. timezone offset should be considered since the ISO time string converts to UTC time, which may cause issues.
Issue

## CSVToArray will return an empty item for documents ending with \n

• 000
https://github.com/30-seconds/30-seconds-of-code/blob/master/snippets/CSVToArray.md CSVToArray('a,b\nc,d\n'); // [ [ 'a', 'b' ], [ 'c', 'd' ], [ '' ] ]
Issue

## Merge two arrays and remove duplicate elements

• 000
Merges two or more arrays and removes any duplicate values i.e. [1,2,3] &amp; [2,3,4] &amp; [4,5,6] = [1,2,3,4,5,6] Can use Map or Set for implementing the solution in O(N) time complexity
Issue

## scrollToTop issue

• 000
when i run scrollToTop , still scroll up when i scroll down manually
Issue

## RGBToHSB returns [NaN, 0, 0] when RGB values are achromatic

• 000
improved: const h = n === 0 ? 0 : n &amp;&amp; v === r ? (g - b) / n : v === g ? 2 + (b - r) / n : 4 + (r - g) / n;
Issue

## Better solution for "Returns the difference between two arrays."

• 000
Why use Set here when we can use includes The solution that is provided is const difference = (a, b) =&gt; { const s = new Set(b); return a.filter(x =&gt; !s.has(x)); }; difference([1, 2, 3], [1, 2, 4]); // [3] But I think there is a better solution available though the time complexity will be exact...
Issue

## Trying to get in touch regarding a security issue

• 000
Hi there, I couldn't find a SECURITY.md in your repository and am not sure how to best contact you privately to disclose a security issue. Can you add a SECURITY.md file with an e-mail to your repository, so that our system can send you the vulnerability details? GitHub suggests that a security poli...
Issue

## Wrong result for some inputs

• 000
In case a doubled digit equals to 0, the sum is miscalculated and the result is wrong. For example, the following valid number returns false instead of true: luhnCheck('4024007174941954'); Or a shorter version: luhnCheck('406'); // false, but should be true A possible solution would be to replace th...