Skip to content

Instantly share code, notes, and snippets.

View Anthodpnt's full-sized avatar

Anthony Du Pont Anthodpnt

View GitHub Profile
@Anthodpnt
Anthodpnt / round-to-decimal.js
Last active December 13, 2016 16:10
Math - Round to Decimal
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <antho.dpnt@gmail.com>
* @site: https://www.twitter.com/JsGists
* @source: Coding Math/Keith Peters
*
* You often get floating numbers in Javascript and sometimes you need to round them and
* keep only n decimals. They are many solutions to do so but let me show you my favorite.
*
* Example:
@Anthodpnt
Anthodpnt / add-leading-zero.js
Last active December 13, 2016 16:09
Formatting - Add Leading Zero
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <antho.dpnt@gmail.com>
* @site: https://www.twitter.com/JsGists
*
* You need sometimes to format you number and one of the common way to format them is to add a leading zero
* to numbers less than 10. There is many ways of doing this so let me show you some of them.
*
* Example:
* I have a number and I want to prepend a 0 to it if it's less than 10.
@Anthodpnt
Anthodpnt / random-array-node.js
Last active December 13, 2016 16:09
Math - Random Array Node
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <antho.dpnt@gmail.com>
* @site: https://www.twitter.com/JsGists
*
* The idea is to get a random node/entry from a given array.
*
* Example:
* I can't choose which fruit I'll eat this afternoon, they all look so tasty so I'll simply close my eyes
* and choose one of them randomly.
@Anthodpnt
Anthodpnt / random-integer.js
Last active December 13, 2016 16:09
Math - Random Integer
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <antho.dpnt@gmail.com>
* @site: https://www.twitter.com/JsGists
*
* The `Math.random()` method only return a random number between 0 and 1.
* But what if you want a larger range than [0, 1] ? We need to improve this
* random method.
*
* Example:
@Anthodpnt
Anthodpnt / node-list-to-array.js
Last active December 13, 2016 16:09
Conversion - NodeList to Array
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <antho.dpnt@gmail.com>
* @site: https://www.twitter.com/JsGists
*
* Methods like `querySelectorAll()` are handy to select multiple DOM elements at once.
* But these methods return a `NodeList` which is a list of all the matching DOM elements.
* No problem at first glance but when you dig a little bit you'll notice there are some
* issues when you want to manipulate them.
*