Skip to content

Instantly share code, notes, and snippets.

View thamsrang's full-sized avatar

Thams thamsrang

  • Chennai, Tamil Nadu, India
View GitHub Profile
@thamsrang
thamsrang / type_coercion.js
Last active October 9, 2019 13:58
JavaScript code tips and tricks. JavaScript Unknown Facts. JavaScript Deep learning. JavaScript Object Conversion. JavaScript Type Conversion. #js #depth
/****
* READ FIRST: https://www.freecodecamp.org/news/js-type-coercion-explained-27ba3d9a2839/
* READ SECOND: https://github.com/denysdovhan/wtfjs
*/
// Coercion is the term that is used for unexpected type casting in JavaScript.
// https://dmitripavlutin.com/javascriptss-addition-operator-demystified/
// http://2ality.com/2012/01/object-plus-object.html
// https://dorey.github.io/JavaScript-Equality-Table/
// https://wtfjs.com/
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
@thamsrang
thamsrang / jskeyterms.md
Last active February 17, 2020 07:59
JavaScript key terms and descriptions. JavaScript Cheat Sheet. #js
@thamsrang
thamsrang / small_algorithms.js
Last active May 17, 2021 13:58
Simple Algorithms #js #algorithms
/**
Find the Max and Min in a Array
For Example: [2, 5, 16, 1]
Max: 16
Min: 1
*/
function findMax(arr){
return Math.max.apply(null, arr);
}
@thamsrang
thamsrang / js-event-terms.md
Last active August 8, 2019 05:53
JavaScript Events #js #events #tutorial

event

An event is a signal that something has happened. All DOM nodes generate such signals (but events are not limited to DOM).

event Handlers

To react on events we can assign a handler – a function that runs in case of an event.

event Delegation

Event Capturing and Event Bubbling allow us to implement one of most powerful event handling patterns called event delegation.

event Bubbling

@thamsrang
thamsrang / random.js
Last active January 25, 2019 09:18 — forked from kerimdzhanov/random.js
JavaScript: get a random number from a specific range. #js #max #min #random
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
@thamsrang
thamsrang / Regex-Patterns.js
Last active November 28, 2018 11:04
Sample Regex Patterns #js #regex
/**
* Password validation RegEx for JavaScript
*
* Passwords must be
* - At least 8 characters long, max length anything
* - Include at least 1 lowercase letter
* - 1 capital letter
* - 1 number
* - 1 special character => !@#$%^&*
*/
@thamsrang
thamsrang / sort-object-properties-by-value.md
Created November 15, 2018 11:45 — forked from umidjons/sort-object-properties-by-value.md
JavaScript: sort object properties by value (numeric or string)

Sort object properties by value (values are text)

I have following object:

var cities={10:'Tashkent', 14:'Karakalpakiya', 16:'Andijan'};

I want sort it by city names, so after sort it should be:

var cities={16:'Andijan', 14:'Karakalpakiya', 10:'Tashkent'};

But I can't sort object properties, instead can convert object into array, then sort items.