Skip to content

Instantly share code, notes, and snippets.

View emfluenceindia's full-sized avatar
📖
Working...

Subrata Sarkar emfluenceindia

📖
Working...
View GitHub Profile
@emfluenceindia
emfluenceindia / hall-column-builder.js
Last active February 13, 2019 13:52
Gutenberg Custom Block for adding columns
/**
* Custom Column control
* Reference: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/columns/index.js
*/
import { times } from 'lodash';
import classnames from 'classnames'
import memoize from 'memize';
/**
@emfluenceindia
emfluenceindia / es6-map-and-keys-in-a-complex-jsvascript-object.js
Last active November 19, 2018 10:59
ES6 - Simple example of how to use Object.keys and Array.map in a complex JavaScript object
/**
The following example is a simple use case of Object.keys and Array.map functions
to loop through a nested JavScript array with object nested into it.
Steps:
1. Used a map() method on the main array, i.e. examResult
2. Started looping through the mapped object
3. If the loop encounters a JavaScript Object (marks in this case) it applied Object.keys method on it
Structure of examResult array:
@emfluenceindia
emfluenceindia / es6-class-and-inheritance-example.js
Created November 19, 2018 07:26
ES6 - A basic example of JavaScript class and inheritance
/**
Declaring Person class, its constructor and methods.
This class will be inherited by GetPerson class later to access its properties and methods.
*/
class Person {
constructor(person) {
this.name = person.name;
this.jobTitle = person.jobTitle;
@emfluenceindia
emfluenceindia / es5-vs-es6-method-definition-in-object-literal.js
Last active November 19, 2018 05:40
ES5 vs ES6 - Function definition in object literal and accessing this keyword
/**
Example 1
The object called 'person' has three properties (location being a nested object)
and one method definition. The method showDetail prints values of different properties
of the same object where the function is defined.
*/
var person = {
fullName: 'Subrata Sarkar',
jobTitle: 'Web developer',
location: {
@emfluenceindia
emfluenceindia / rest-parameter-and-spread-operator.js
Last active November 16, 2018 14:38
Rest Parameter and Spread Operator in ES6 - How they work
/**
ES6 has provided us two very powerful methods - Rest Parameters and Spread Operators.
In this example I have tried to explain these methods, how they work and what we can get out of them.
Rest Parameter and Spread Operator have made code clean and easier to understand.
With these methods, the development time has decreased considerably as well.
Before going into code example, some key points which I want to mention.
1. Both Rest Parameter and Spread Operator use the sanme ‘...’ syntax.
@emfluenceindia
emfluenceindia / es6-named-parameter-with-multiple-return-value-example.js
Last active November 14, 2018 12:21
ES6 - Example of handling named parameter and multiple return value using object destructuring
/**
The following code snippet shows how to use named parameters
by using the help of Object Destructuring.
Function emiCalculator() takes one argument whcih is a destructured object with
multiple entries, of which two have default values set (in ES6 we can set default values for parameters)
When calling the function we would pass three values i.e. rawPrice and downPayment and emiCount (although it has a
default value set) and won't pass any value for 'interestPerAnum'.
For destructured parameters we have pass their values like { parameterName: {properyName: value} }
@emfluenceindia
emfluenceindia / es6-multiple-return-value-and-object-destructuring.js
Last active November 14, 2018 06:15
ES6 example of handling Multiple Return Value from a function and application of Destructuring
/**
A simple example showing how Multiple return values are handled in ES6 and then further modified it using Object Destructuring.
I have used ES6 function syntax and ES6 template literal approach in this example.
*/
// Function to return multiple values (properties) bundled inside a JavaScript object.
const compoundInterestCalculator = ( amount, roi, compoundingTimesPeryear, years ) => {
const maturityAmount = (amount * Math.pow((1 + (roi/(compoundingTimesPeryear*100))), (compoundingTimesPeryear*years)));
@emfluenceindia
emfluenceindia / es6-object-destructuring-simple-example.js
Last active November 14, 2018 04:43
ES6 Object Destructuring - How it works: Simple example
//Declare a JavaScript complex object
const user = {
name: 'Subrata Sarkar',
age: 47,
gender: 'Male',
location: {
address: {
aptno: 'D3',
bldg: 'City Heights - Phase 9',
@emfluenceindia
emfluenceindia / es6-default-parameter-in-class-example.js
Created November 12, 2018 14:26
Default Parameters in ES6 - in classes
/**
A simple example of default parameter handling inside a JavaScript class which uses a constructor
*/
class paramValueExample {
constructor(x, y) {
this.x = 25;
this.y = 50;
this.fruits = ['banana', 'apple', 'grapes'];
@emfluenceindia
emfluenceindia / es6-default-parameter-example.js
Last active November 12, 2018 14:12
Default Parameters in ES6
// Default parameter syntax in ES6
// Until ES5 we were not able to declare a default value to function paramters
// ES6 gives us the liberty to do that
// Parameters value type has no restriction, it could either be an Integer or a String or an Array or even a JavaScript object
// *************************************************
// THE ES5 WAY: Let's see how we use to do it in ES5
// *************************************************/
var objAboutPerson = {