Skip to content

Instantly share code, notes, and snippets.

View ramsunvtech's full-sized avatar
💭
Full Stack Developer (Java, React, React Native)

Venkat.R ramsunvtech

💭
Full Stack Developer (Java, React, React Native)
View GitHub Profile
"use strict";
const tree = {
left: null,
right: null,
parent: null,
value: '0',
};
const node1 = {
@ramsunvtech
ramsunvtech / isMultipleOf.js
Last active June 30, 2019 12:34
`isMultipleOf` Promise Function which resolves if input is multiple of number or rejects it
function isMultipleOf(input, number) {
if (input % number === 0) {
return Promise.resolve(input);
}
return Promise.reject(new Error(`not a multiple ${input}`));
}
isMultipleOf(20, 10).then(console.log, console.error)
@ramsunvtech
ramsunvtech / pass-data-to-props.children.js
Created June 27, 2019 10:44
Pass data to Props.Children
{
React.cloneElement(props.children, { props1: propsValue });
}
@ramsunvtech
ramsunvtech / redux-logger.js
Created January 14, 2019 18:16
Redux Logger
import { compose, createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import thunkMiddleware from 'redux-thunk';
const middlewares = [
thunkMiddleware,
];
if (process.env.NODE_ENV !== 'production') {
const createLogger = require('redux-logger');
@ramsunvtech
ramsunvtech / longBeats.js
Created September 29, 2018 23:36
Largest Number of Beads Problem
function solution(A) {
let longest = [];
let uniqueList = [];
let lengthList = [];
if (!Array.isArray(A) || A.length === 0) {
return 0;
}
for (let i = 0; i < A.length; i++) {
@ramsunvtech
ramsunvtech / arrayMultiply.js
Created September 25, 2018 20:57
Array Multiply Prototype Method
let integerLists = [1,2,3];
Array.prototype.multiply = function (callback) {
let list = [];
for(let i= 0; i < this.length; i++) {
list.push(callback(this[i], i));
}
return list;
};
@ramsunvtech
ramsunvtech / simpleClosure.js
Created September 25, 2018 20:38
Simple Closure Example
function init() {
var a = [];
function airPlane(val) {
a.push(val);
return a;
}
return airPlane;
}
var airPlane = init();
@ramsunvtech
ramsunvtech / capitalize.js
Created September 25, 2018 20:26
Capitalize the uneven Case String
function titleCase(str) {
return str.toLowerCase().split(' ').map((word) => `${word[0].toUpperCase() + word.slice(1)}` ).join(' ');
}
titleCase("hEllo wORld"); // "Hello World"
@ramsunvtech
ramsunvtech / divideByMinus.js
Created September 25, 2018 20:11
Divide without Slash Symbol
function divideByMinus (a, b) {
var i = 0;
while(a >= b) {
i++;
a = a - b;
}
return i;
}
@ramsunvtech
ramsunvtech / sumOfArray.js
Created September 25, 2018 19:42
Sum of Three Arrays
var a = [1,2,3,1,1];
var b = [4,5,6,1];
var c = [1,1,1];
function sumArray(a,b,c) {
const max = Math.max(a.length, b.length, c.length);
const sumList = [];
for(let i = 0; i < max; i++) {
sumList.push((a[i] || 0) + (b[i] || 0) + (c[i] || 0));