Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options questions only not deleted user 53773

JavaScript is a versatile, high-level programming language. It is the programming language in all browsers.and can be used for back-end programming with node.js. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.

20 votes
4 answers
341 views

"The 2nd Monitor" chatroom translator

For those who go to The 2nd Monitor chatroom, you already know how bad I am at remembering everything. And, sometimes, the new visitors will wonder what something means. For that, I've developed a ve …
Ismael Miguel's user avatar
3 votes
2 answers
1k views

Function queue for synchronous execution

The purpose of this code is to allow to add functions to a queue, that will execute them sequentially. With this in mind, it also allows to execute them with a defined delay, to prevent them from blo …
Ismael Miguel's user avatar
8 votes
1 answer
430 views

Simple syntax highlighter in Javascript - SQL highlighting

Yesterday and today I've made a very basic syntax highlight. It creates a function in the window object that handles part of the job: (function(window){ var f=window.highlight = function(lang, …
Ismael Miguel's user avatar
2 votes
1 answer
85 views

Equalized PRNG number distribution

The main idea behind this code is to distribute multiple random numbers, but guarantee that the probability of each coming is equal. The code is really basic: ( function( window ){ window.RNG = …
Ismael Miguel's user avatar
1 vote
1 answer
46 views

Equalized PRNG number distribution - Part 2

A few days ago, I've made a code to equally distribute a set of numbers and retrieve them randomly. Today, I've rewritten the code (most of it, at least). I've followed most of the advice and tried to …
Ismael Miguel's user avatar
8 votes
2 answers
7k views

Simple function to verify if a number is integer

Since JavaScript doesn't distinguish between both, I've made an extremelly basic function. function isInteger(num){ var numCopy = parseFloat(num); return ! … Examples of results: 1.0: true (JavaScript treats <n>.0 as an integer) 1e3: true 1.2345e2: false (equivalent to 123.45) 1.2345e5: true (equivalent to 123450) 1e200: true (equivalent to Infinity) Is …
Ismael Miguel's user avatar
2 votes
2 answers
12k views

Simple function to generate an HTML-safe string

Sometimes, we have to do some fixing to insert a string into an HTML property. Or just to display it. But not everything is safe! Consider the following example: document.getElementById('name').inn …
Ismael Miguel's user avatar
1 vote
2 answers
1k views

Re-implementing Javascript's String.prototype.indexOf

I had this idea of trying to re-implement the function String.prototype.indexOf in a way that could potentially be faster than the native function. With some testing, I've doodled the following funct …
Ismael Miguel's user avatar
0 votes
2 answers
344 views

PageVisibility API, to handle page/tab visibility changes

Currently, I'm working on a project where I needed to run some code every time the page is hidden. I searched high and low and found this question: Is there a way to detect if a browser window is not …
Ismael Miguel's user avatar
0 votes
1 answer
1k views

jQuery .validate() plugin, additional method to validate numbers

It fulfills all my needs, but relies on a really bad behaviour in Javascript, which is that objects are passed as a reference. … It also relies on Javascript being executed linearly, instead of having multiple threads, which is REALLY bad! How can I re-write this in a clean and decent way? …
Ismael Miguel's user avatar
1 vote
0 answers
792 views

Image color reduction

Just for the fun of it, I was looking of ways to make true-color GIFs. I've started to write the code, and it clicked me: this won't work for that, but it does make a nice color-reduction method. Bas …
Ismael Miguel's user avatar
4 votes
1 answer
408 views

Bootstrap file input styler

This simple JavaScript code styles all file inputs to match with Bootstrap's style. …
Ismael Miguel's user avatar
6 votes
1 answer
2k views

Polyglot array_extend() function for Javascript and PHP

The goal is to grab n arrays (or Javascript Objects) and 'extend' them in order to obtain a single array with all the values. This function runs both in Javascript and PHP. … $result = $javascript ? new Object() : array(); $arguments = $javascript? …
Ismael Miguel's user avatar
4 votes
1 answer
132 views

Polyglot function to sum all the numbers in an array in Javascript and PHP

This is due to the limitations of Javascript. … is just to save if we are running in Javascript or PHP). …
Ismael Miguel's user avatar
5 votes
2 answers
1k views

List all repeated substrings with a fixed length

While fiddling around, I've made a very simple and naive function to retrieve any repeated sub-string within a certain string. function getRepetitions(str, length){ if(isNaN(length)) { …
Ismael Miguel's user avatar

15 30 50 per page