Author Archives: shahprashant

A simple todo app in javascript

Asked in Box onsite interview. With a node.js server on backend. $().ready(function() { $(‘#add’).on(‘click’, addTask); $(‘#tasks’).on(‘click’, markComplete); // Alternative way // var tasksElement = document.getElementById(‘tasks’); // tasksElement.addEventListener(‘click’, markComplete); //document.getElementById(‘task-input’).onkeydown = function(e){ $(‘#task-input’).on(‘keydown’, function(e) { if(e && e.keyCode == 13){ addTask(); … Continue reading

Posted in Javascript | Leave a comment

System Design Resources

Grokking the System Design Interview https://www.educative.io/collection/5668639101419520/5649050225344512

Posted in General | Leave a comment

Atlassian Hackerrank Interview

1) Implement a method ‘find’ that will find the starting index (zero based) where the second list occurs as a sub-list in the first list. It should return -1 if the sub-list cannot be found. Arguments are always given, not … Continue reading

Posted in Algorithms | Leave a comment

Authentication for REST Apis

https://hashedin.com/2016/07/05/choosing-right-authentication-for-rest-apis/

Posted in Concepts | Leave a comment

Combinations of a String

Implement a function that prints all possible combinations of a string. A string “12” is the same as string “21” function combine($instr, $outstr, $index) { for ($i = $index; $i < strlen($instr); $i++) { $outstr = $outstr . $instr[$i]; echo … Continue reading

Posted in Algorithms | Leave a comment

Simulate a debounce function

http://obscurejavascript.tumblr.com/post/115595038489/debounce-in-javascript var debounce = function(callback, delay) { var timeout = null; return function() { var args = arguments, context = this; clearTimeout(timeout); timeout = setTimeout(function() { callback.apply(context, args); }, delay); }; };

Posted in Javascript | Leave a comment

Debounce and Throttle in Javascript

Throttle: the original function be called at most once per specified period. Example: while window resizing Debounce: the original function be called after the caller stops calling the decorated function after a specified period. Example: Validating contents of a text … Continue reading

Posted in Javascript | Comments Off on Debounce and Throttle in Javascript

Trulia On Site Questions

1) How does Oauth work ? 2) Explain journey of a URL ? 3) How does caching work in a CDN? How do you push a new file out to CDN? 4) Emulate the throttle function() // Allow callback to … Continue reading

Posted in Javascript | Leave a comment

IIFE in Javascript (Immediately Invoked Function Expression)

http://benalman.com/news/2010/11/immediately-invoked-function-expression/

Posted in Javascript | Leave a comment

How to achieve static variable in javascript

2 Ways : 1) Make use of the fact that functions are objects and can have properties (Even using “this” instead of uniqueID inside the function will do) function uniqueID() { // Check to see if the counter has been … Continue reading

Posted in Javascript | Leave a comment