Blog Archives

Check if same key pressed twice in 1second

var twice = 0; var previous_key=null; $(document).on(‘keyup’, function( e ){ if(twice===1){ if(e.which==previous_key) console.log(previous_key+'(you pressed twice!)’+e.which); else{ console.log(previous_key+’—–‘+e.which); twice = 0; } }else{ previous_key=e.which; } twice = 1; setTimeout(function(){ // …reset to 0 after 1s twice = 0; }, 1000); });

Posted in Javascript

Get first unique element of string

Problem: Suppose you are given a string and your task is to find the first unique element of that string. str = “bcdadbdcfd” Ruby Way: def first_uniq(str) a = diff = [] dup = [] #seperate array assigned due to

Tagged with: , ,
Posted in Interview questions, Javascript, Ruby
StackOverFlow
Categories
Archives