30 seconds of code
These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.
Click on a snippet's name to view its code.
Converts a JSON object to a date.
Use recursion. Similar to
Array.prototype.indexOf() that finds the index of a value within an array.
The difference being this operation only works with sorted arrays which offers a major performance boost due to it's logarithmic nature when compared to a linear search or
Celsius to Fahrenheit temperature conversion.
Removes any properties except the ones specified from a JSON object.
Applies the Collatz algorithm.
number of vowels in provided string.
Returns the array of factors of the given
If the second argument is set to
true returns only the prime factors of
0 returns an empty array.
num is less than
0 returns all the factors of
-int together with their additive inverses.
Array.prototype.filter() to find all the factors of
num is negative, use
Array.prototype.reduce() to add the additive inverses to the array.
Return all results if
false, else determine and return only the prime factors using
Omit the second argument,
primes, to return prime and non-prime factors by default.
Fahrenheit to Celsius temperature conversion.
Returns the number of fibonnacci numbers up to
Generates an array, containing the Fibonacci sequence, up until the nth term.
Returns the area of a triangle using only the 3 side lengths, Heron's formula. Assumes that the sides define a valid triangle. Does NOT assume it is a right triangle.
More information on what Heron's formula is and why it works available here: https://en.wikipedia.org/wiki/Heron%27s_formula.
Returns the number of times
num can be divided by
divisor (integer or fractional) without getting a fractional answer.
Works for both negative and positive integers.
DELETE request to the passed URL.
PUT request to the passed URL.
Checks if the given number is an Armstrong number or not.
Determines if the
pattern matches with
Convert kilometers/hour to miles/hour.
Convert miles/hour to kilometers/hour.
Logs a value and returns it.
QuickSort an Array (ascending sort by default).
Returns all the vowels in a
str replaced by
Solves the given mathematical expression in reverse polish notation.
Throws appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :-
** are the exponential symbols and are same). This snippet does not supports any unary operators.
Performs speech synthesis (experimental).
window.speechSynthesis.getVoices() to convert a message to speech.
window.speechSynthesis.speak() to play the message.
Squares each number in an array and then sums the results together.