Skip to content

Tag: javascript

When to use NodeIterator

Benchmark compares QSA & .forEach vs a NodeIterator Now either NodeIterator’s suck or I’m doing it wrong. Question: When should I use a NodeIterator ? In case you don’t know, DOM4 specifies what NodeIterator is. Answer It’s slow for a variety of reasons. Most obviously is the fact …

Determine if string is in base64 using JavaScript

I’m using the window.atob(‘string’) function to decode a string from base64 to a string. Now I wonder, is there any way to check that ‘string’ is actually valid base64? I would like to be notified if the string is not base64 so I can perform a different action. Answer If “v…

Converts minutes into days, week, months and years

Let’s suppose I have a number which represents the minutes passed from the start time to now. I wan to create a function which returns the years, months, week and days corresponding to the minutes I am passing to that function. Here an example: What is the best way to achieve the result? Answer Maybe li…