Skip to content

Instantly share code, notes, and snippets.

View revanth0212's full-sized avatar

Revanth Kumar Annavarapu revanth0212

View GitHub Profile
@revanth0212
revanth0212 / HowToUseFieldCalculator.js
Created August 5, 2018 17:06
A sample to show how to use the field changes calculator.
const calculator = require('field-change-effects-calculator');
const changesCalculator = calculator(rules);
const calculateChanges = (event) => {
const state = getState()
const { name, value } = event.target
const changes = changesCalculator(state)(name, ['path', 'of', 'field', 'in', 'the', 'state', 'object'], value)
return changes
}
@revanth0212
revanth0212 / CountryAndPhoneNumberRules.js
Last active August 5, 2018 01:45
This is a sample rules object that shows the interaction between country and phone number fields in a state object.
const rules = {
country: [
{
name: 'phoneNumber',
path: ['fields', 'phoneNumber'],
props: (countryNewValue, state) => ({
editable: countryNewValue && countryNewValue !== '',
countryPhoneCode: countryPhoneCodeMapper[countryNewValue]
})
}
.OpsPortalCore {
width: 100%;
height: 100%;
padding-top: 50px;
}
.chargeInput input {
color: rgba(255, 255, 255, 1) !important;
text-align: center !important;
background-color: rgba(13, 93, 184, 1) !important;
/**
*** SIMPLE GRID
*** (C) ZACH COLE 2016
**/
@import url(https://fonts.googleapis.com/css?family=Lato:400,300,300italic,400italic,700,700italic);
/* UNIVERSAL */
html,
@revanth0212
revanth0212 / FindKthLargest-BST.js
Created June 24, 2018 22:35
Find the Kth largest element in a stream using a BST.
function Node(val) {
this.val = val
this.rightCount = 1
this.left = null
this.right = null
}
/**
* @param {number} k
* @param {number[]} nums
@revanth0212
revanth0212 / LowestCommonAncestor.js
Created June 24, 2018 18:32
Find the lowest common ancestor of 2 nodes in a BST.
class Relationship {
constructor(root) {
this.relObj = {}
this.iterate(root, null, 0)
}
iterate(root, parent, level) {
if (root) {
this.relObj[root.val] = { level: level, parent: parent }
this.iterate(root.left, root, level + 1)
@revanth0212
revanth0212 / InorderSuccessor.js
Created June 24, 2018 00:40
Find the In-Order Successor of a node in a BST.
class Stack {
constructor(root) {
this.stack = []
while (root) {
this.stack.push(root)
root = root.left
}
}
hasNext() {
@revanth0212
revanth0212 / NumberOfWaysToClimbNStairs.js
Created June 23, 2018 16:09
Find the number of ways to climb N number of stairs. (DP)
const hashMap = {}
function countNumberOfWays (steps) {
if (steps <= 0) {
return 0
} else if (steps === 1) {
return 1
} else if (steps === 2) {
return 2
} else {