This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
eg. [1,2,3,9] Sum = 8, Output = -1 //not found | |
[1,2,4,4] Sum = 8, Output = 2,3 //found (return the index of matched elements) | |
Assumption - input array is sorted | |
This solution here is the fastest way, which is O(n) - linear time | |
*/ | |
function findElementsThatAddToASum(arr, sum) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an input object | |
var obj = { | |
a: { | |
b: 1, | |
c: 1, | |
d: { | |
e: 1, | |
f: 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Binary Search | |
//Runtime - O(log n) | |
//Faster than Linear search | |
function binarySearch(arr, num) { | |
//sort the array | |
//arr.sort() modifies the original array | |
arr.sort(function(a, b) { | |
return a - b; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Normal fibonacci - No Memoization | |
//Fib series - 1 1 2 3 5 8 13 21 34 ... | |
//O(2^n) = exponential time complexity | |
function fib(n) { | |
if(n <= 2) { | |
return 1; | |
} | |
return fib(n-2) + fib(n-1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Imagine we have a <div id="myDiv"></div> element. Suppose a new element <div class='new-element'></div> is appended | |
to the parent. Write a JS function that can do event delegation to an element that will be added in future. */ | |
var parentRef = document.getElementById('myDiv'); //document.querySelector('#myDiv') | |
function delegate(type, elRef, callback) { | |
parentRef.addEventListener(type, function(evt) { | |
document.querySelectorAll(elRef).forEach(function(el) { | |
if(el === evt.target) { | |
callback.call(null, evt); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>iron-list dynamic list item</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes"> | |
<meta name="mobile-web-app-capable" content="yes"> | |
<meta name="apple-mobile-web-app-capable" content="yes"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../yodlee-component/yodlee-scaffold.html"> | |
<link rel="import" href="../yodlee-component/yodlee-navigation.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-account-summary.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-recent-transactions.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-profile-card-bundled.html"> | |
<link rel="import" href="../yodlee-component/yodlee-notifications.html"> | |
<polymer-element name="my-element"> | |
<template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../yodlee-component/yodlee-scaffold.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-account-summary.html"> | |
<link rel="import" href="../yodlee-component/yodlee-navigation.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-recent-transactions.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-profile-card-bundled.html"> | |
<link rel="import" href="../yodlee-component/yodlee-notifications.html"> | |
<polymer-element name="my-element"> | |
<template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../yodlee-component/yodlee-scaffold.html"> | |
<link rel="import" href="../yodlee-component/yodlee-navigation.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-recent-transactions.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-account-summary.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-profile-card-bundled.html"> | |
<link rel="import" href="../yodlee-component/yodlee-notifications.html"> | |
<polymer-element name="my-element"> | |
<template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../yodlee-component/yodlee-scaffold.html"> | |
<link rel="import" href="../yodlee-component/yodlee-navigation.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-account-summary.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-recent-transactions.html"> | |
<link rel="import" href="../yodlee-component/yodlee-notifications.html"> | |
<link rel="import" href="../hackathon-elements/yodlee-profile-card-bundled.html"> | |
<polymer-element name="my-element"> | |
<template> |