Skip to content

Instantly share code, notes, and snippets.

View kirantemojo's full-sized avatar

Kiran kirantemojo

  • Hyderabad
  • India
  • 02:27 (UTC +05:30)
View GitHub Profile
@kirantemojo
kirantemojo / max-draws.js
Last active January 25, 2017 21:09
Hackerrank - Max draws - JavaScript
/**
* Hackerrank Solution - Max draws
*/
function processData(input) {
var data = input.split("\n")
var t = data[0];
for (var i = 1 ; i <= t; i += 1) {
var n = data[i].match(/\d+/g);
console.log(parseInt(n) + 1);
}
@kirantemojo
kirantemojo / handshake.js
Last active January 25, 2017 21:09
Hackerrank - Hand shake - Javascript
/**
* Hackerrank Solution - Handshake
*/
function main() {
var T = parseInt(readLine());
for(var a0 = 0; a0 < T; a0++){
var N = parseInt(readLine());
console.log(Math.floor(N * (N - 1)/2));
}
}
@kirantemojo
kirantemojo / circular-array-rotation.js
Created January 22, 2017 11:46
Hackerrank : Circular array rotation
function main() {
var n_temp = readLine().split(' ');
var n = parseInt(n_temp[0]);
var k = parseInt(n_temp[1]);
var q = parseInt(n_temp[2]);
a = readLine().split(' ');
a = a.map(Number);
var rot = k%n;
for(var a0 = 0; a0 < q; a0++) {
@kirantemojo
kirantemojo / find-a-point.js
Last active January 22, 2017 11:26
Hackerrank - find a point
function findPoint(input) {
var data = input.split("\n")
var n = data[0];
for (var i = 1 ; i <= n; i += 1) {
var pq = data[i].match(/\d+/g).map(Number);
console.log((pq[2] + (pq[2] - pq[0])) + " " + (pq[3] + (pq[3] - pq[1])));
}
}
@kirantemojo
kirantemojo / 0_reuse_code.js
Created June 28, 2016 13:46
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
/**
* Static class - this new MyClass will create scope but with same objects and class which are static, which tells that tells being as
* a static class, it can be told as MyClass will not be `this` giving its reference to MyClass for all instances
* and can shared
*/
function MyClass()
{
function add(num1, num2) { return (num1+num2); }
function sub(num1, num2) { return (num1-num2); }
/**
* Creating multiple constructors @ each instance
* @constrctor
* /
function Foobar(foobar) {
this.foobar = foobar;
}
Foobar.prototype = {
foobar: null
/**
* Global error event handler in javascript in browser in both async and sync operations
* window - signifies the browser context
* 'error' - event name
* @param e Evemt object of the error occurred to print the stack
* /
window.addEventListener('error', function (e) {
var stack = e.error.stack;
var message = e.error.toString();
if (stack) {
@kirantemojo
kirantemojo / largest_number.js
Created March 19, 2016 16:32
Largest Integer Number
/**
* Largest integer number in javascript
* @type {number}
*/
var x = 9007199254740992;
var y = -x;
x == x + 1; // true !
y == y - 1; // also true !
/**
@kirantemojo
kirantemojo / skill-meter.js
Created March 18, 2016 15:12
Skill Meter - Javascript Module with DOM & SCSS
/*============================================
Progress Indicator - Skill Meter
*===========================================*/
/**
* DOM looks like below
* <div class="progress pr_progress" data-value="80"></div>
*/
/**