Skip to content

Instantly share code, notes, and snippets.

View Darth-koder007's full-sized avatar

Vijay Singh Darth-koder007

View GitHub Profile
@Darth-koder007
Darth-koder007 / infiniteAdd.js
Last active November 28, 2018 07:04
add arguments in all invocations and return sum
/**
* @description
* sumMaker(2,3)(4,5)(6,7)
* Above operation yields 27
*/
function sumMaker() {
var sumMain = Array.prototype.reduce.call(Array.prototype.slice.call(arguments), function(acc, curr) {
return acc + curr
});
@Darth-koder007
Darth-koder007 / bind.js
Last active November 20, 2018 03:53
polyfill for bind
Function.prototype.bind = function(othis) {
// Check of 'this' is a function
if (typeof this !== 'function') {
throw new Error('What is trying to be bound is not callable');
}
var args = Array.prototype.slice.call(arguments, 1);
var fNOP = function() {};
var fToBind = this;
var boundFn = function() {
@Darth-koder007
Darth-koder007 / flattenArray.js
Created November 4, 2018 05:02
Flatten Array
// Flatten array function
// @arguments array
function flatten(arr) {
var newArr = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i]) {
if (Array.isArray(arr[i])) {
newArr = newArr.concat(flatten(arr[i])); // Recursive call to flatten
} else {
newArr.push(arr[i]);
@Darth-koder007
Darth-koder007 / settings.json
Created July 14, 2018 08:08
html css javascript settings for visual studio code beautify plugin
{
"editor.formatOnSave": true,
"beautify.config": {
"end_with_newline": true,
"wrap_line_length": 80,
"indent_handlebars": true,
"indent_inner_html": true,
"wrap_attributes": "force-aligned",
"newline_between_rules": true,
"space_around_combinator": true,
@Darth-koder007
Darth-koder007 / BreadthFirstSearch.js
Last active February 10, 2018 18:14
DS in JS: breadFirstSearch
// Breadth First Search on graph
let BFS = (graph, startItem, callBack) => {
if (!graph[startItem]) { return false; }
let searched = [];
let currentQueue = [];
currentQueue.push(startItem);
while (currentQueue.length && currentQueue.length > 0) {
let currentNode = currentQueue.shift();
@Darth-koder007
Darth-koder007 / HashMap.js
Created January 19, 2018 13:20
Data Structures in Javascript: HashTable HashMap
/**
* HashTable in JS
**/
/**
* @description hashnode
*/
class HashNode {
constructor(key, value, next) {
this.key = key;
@Darth-koder007
Darth-koder007 / BinarySearchTree.js
Created January 19, 2018 08:24
Data structures in Javascript: Binary Tree
/**
* Binary Tree in javascript
**/
class BST {
constructor(value) {
this.value = value;
this.right = null;
this.left = null;
}
@Darth-koder007
Darth-koder007 / LinkedList.js
Created January 19, 2018 04:04
Data structures in javascript: Linked list
/**
*
* Linked List in javascript
*
**/
/**
*
* Class node
*
**/
@Darth-koder007
Darth-koder007 / hacker rank hourglass.js
Last active June 16, 2017 11:25
hacker rank hourglass created by Darth-koder007 - https://repl.it/ImaY/13
/**
* HourGlassProblem Class
*/
class HourGlassProblem {
/**
* HourGlassProblem class constructor
* @param {Array} hourGlassCollection
*/
constructor(hourGlassCollection) {