Skip to content

Instantly share code, notes, and snippets.

View ronit-mukherjee's full-sized avatar

Ronit Mukherjee ronit-mukherjee

View GitHub Profile
//JS Fiddle Link:- https://jsfiddle.net/mukherjeeronit/3ob2gyz9/7
function StudentManagementSystem() {
var students = []; //Private Variable
function _getStudentById(id) { //Private Method
for (var i = 0; i < students.length; i++) {
var student = students[i];
if (student.id == id) {
return i;
}
@ronit-mukherjee
ronit-mukherjee / anonymous-function-use-case.js
Created November 30, 2018 01:05
Use of Anonymous Function as Callback Function
var currentStudentCount = 10;
function getNewlyAddedStudentCount(callbackFn){ // Anonymous function captured in "callbackFn" variable
setTimeout(function(){
callbackFn(5); // "callbackFn" variable used to call the anonymous function received as parameter
},1000);
}
function printStudentCount(){
getNewlyAddedStudentCount(function(newlyAddedCount){ //Anonymous function passed as parameter to another function
@ronit-mukherjee
ronit-mukherjee / solution.js
Created November 29, 2018 00:07
Solving the problem of asynchronous function flow using callback
//Solution to problem mentioned in https://codepen.io/ronit-mukherjee/pen/rQrpJZ
//A Local variable having last updated count of friends for the loggedin user
let frndsCount = 65;
//A function to fetch the latest count of friends from the server for the loggedin user
const fetchFrndsCountFromServer = (callbackFn) => {
setTimeout(()=>{ //Emulating an Asynchronous API call which takes 1000 i.e 1 Sec to fetch data from server
@ronit-mukherjee
ronit-mukherjee / problem.js
Last active November 29, 2018 00:09
A problem showing the need of callback function
//A Local variable having last updated count of friends for the loggedin user
let frndsCount = 65;
//A function to fetch the latest count of friends from the server for the loggedin user
const fetchFrndsCountFromServer = () => {
setTimeout(()=>{ //Emulating an Asynchronous API call which takes 1000 i.e 1 Sec to fetch data from server
return 87;
},1000);
}
@ronit-mukherjee
ronit-mukherjee / gulpfile.js
Last active September 26, 2018 08:44
Boilerplate to setup project with support of Bootstrap 4, ES6 and Live Reload using Gulp
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
const browserSync = require('browser-sync').create();
const htmlmin = require('gulp-htmlmin');
const inject = require('gulp-inject');
const minifyJS = require("gulp-uglify");
@ronit-mukherjee
ronit-mukherjee / main.js
Created August 28, 2018 14:10
HackerRank - Bithday Cake Candle (JS)
//https://www.hackerrank.com/challenges/birthday-cake-candles/problem
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
@ronit-mukherjee
ronit-mukherjee / main.js
Created August 28, 2018 12:53
HackerRank - Mini-Max sum (JS)
//https://www.hackerrank.com/challenges/mini-max-sum/problem
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
@ronit-mukherjee
ronit-mukherjee / main.js
Created August 28, 2018 12:51
HackerRank - Right Aligned Triangle (JS)
//https://www.hackerrank.com/challenges/staircase/problem
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
@ronit-mukherjee
ronit-mukherjee / main.js
Created August 28, 2018 11:23
HackerRank - Diagonal Difference (JS)
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
@ronit-mukherjee
ronit-mukherjee / FacebookLoginButton.js
Created July 23, 2018 01:47
React Facebook Login Button Component
/*global FB*/
import React, {Component} from 'react';
class FacebookLoginButton extends Component{
componentDidMount() {
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}