Last active
April 10, 2019 20:09
-
-
Save ArunHub/ce28cc35a0d52608f81b39180dca78d2 to your computer and use it in GitHub Desktop.
rvp is for practise instant code in desktop
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
let ia=0, ib=0, an=a.length, bn=b.length; | |
let r=[]; | |
while(ia<an && ib<bn) { | |
let iia = ia; | |
let iib = ib; | |
let bb = b.charAt(ib); | |
while(a.charAt(iia)<=bb) iia++; | |
r.push(a.substring(ia,iia)); | |
ia=iia; | |
let aa = a.charAt(ia); | |
while(b.charAt(iib)<aa) iib++; | |
r.push(b.substring(ib,iib)); | |
ib=iib; | |
} | |
if (ia<an) r.push(a.substring(ia,an)); | |
if (ib<bn) r.push(b.substring(ib,bn)); | |
return r.join(''); | |
// | |
rotate = (a,r) => { | |
let x = a[0].length; | |
let y = a.length; | |
let n = Math.floor(Math.min(x,y)/2); | |
for(k=0;k<n;k++) { | |
let xx = x-2*k; | |
let yy = y-2*k; | |
let rr = r % (2*(xx-1+yy-1)); | |
let aa = []; | |
for(i=0;i<xx;i++) { | |
aa.push(a[k][k+i]); | |
} | |
for(i=1;i<yy-1;i++) { | |
aa.push(a[k+i][x-k-1]); | |
} | |
for(i=xx-1;i>=0;i--) { | |
aa.push(a[y-k-1][k+i]); | |
} | |
for(i=yy-2;i>0;i--) { | |
aa.push(a[k+i][k]); | |
} | |
aa = aa.splice(rr,aa.length).concat(aa.splice(0,rr)); | |
for(i=0;i<xx;i++) { | |
a[k][k+i] = aa.shift(); | |
} | |
for(i=1;i<yy-1;i++) { | |
a[k+i][x-k-1] = aa.shift(); | |
} | |
for(i=xx-1;i>=0;i--) { | |
a[y-k-1][k+i] = aa.shift(); | |
} | |
for(i=yy-2;i>0;i--) { | |
a[k+i][k] = aa.shift(); | |
} | |
} | |
return a; | |
} |
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
function solution(s) { | |
let isPrime = (r)=>{ | |
for (var i = 2; i <= Math.floor(Math.sqrt(r)); i++) { | |
if (r % i === 0) | |
return false; | |
return true; | |
} | |
} | |
for(var u=0; u<5;u++){console.log(u);if(u==2) {return true}} | |
let n = s.length; | |
let max = -1, maxStr = ""; | |
for (var i = 0; i < n - 1; i++) { | |
for (var j = n - 1; j > i; j--) { | |
let t = j - i + 1 | |
, len = 0; | |
while (i + len < j - len && s.charAt(i + len) === s.charAt(j - len)) { | |
len++; | |
} | |
if(t===len*2 || t===len*2+1){ | |
if(max<t){ | |
max=t; | |
maxStr = s.substring(i,j+1); | |
} | |
} | |
} | |
} | |
if(max!==1 && isPrime(max)){ | |
return "YES"; | |
}else{ | |
return "NO"; | |
} | |
} | |
solution('random1232321random'); |
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
function isPalin(text){ | |
text = text.replace(/ /g, '').toLowerCase(); | |
let retVal = true; | |
let n = text.length; | |
for(let i=0;retVal && i<n/2;i++){ | |
retVal = (text.charAt(i) == text.charAt(n-i-1)); | |
} | |
return retVal; | |
} |
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>rvp</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<style type="text/css"> | |
body { | |
/*height: 100vh;*/ | |
background: darkslategray; | |
} | |
/* body:hover{ | |
background: white; | |
}*/ | |
</style> | |
<style type="text/css"> | |
/*iframe[id^=sidebanner] {*/ | |
.iframe html { | |
width: 80px; | |
-webkit-transition: all ease 100ms; | |
-moz-transition: all ease 100ms; | |
-ms-transition: all ease 100ms; | |
-o-transition: all ease 100ms; | |
transition: all ease 100ms; | |
background: darkslategray; | |
} | |
/* .aa:hover .iframe { | |
width: 50%; | |
}*/ | |
.btn { | |
display: block; | |
} | |
/* .btn:hover + iframe { | |
display: block; | |
width: 50%; | |
}*/ | |
.iframe html:hover { | |
width: 50%; | |
} | |
/* @media (max-width: 2500px) { | |
.aa iframe:hover { | |
width: 50%; | |
} | |
}*/ | |
/* | |
@media all and (max-width: 900px) { | |
iframe[id^=sidebanner]:hover { | |
width: 55%; | |
} | |
} | |
*/ | |
/* .a { | |
border: solid blue; | |
height: 20px; | |
} | |
.b { | |
display: none; | |
border: solid green; | |
} | |
.a:hover+.b { | |
display: block; | |
} | |
.b:hover { | |
display: block; | |
} | |
.b iframe { | |
position: relative; | |
z-index: -1; | |
} | |
.c { | |
display: none; | |
} | |
button:hover+.c { | |
display: block; | |
}*/ | |
input[type=email]:invalid { | |
border: 5px solid red; | |
} | |
input[type=email]:valid { | |
border: 5px solid lightgreen; | |
} | |
</style> | |
</head> | |
<body class="aa"> | |
<!-- <button class="btn">click me</button> | |
<iframe class="iframe" id="sidebanner" src="" allowtransparency="true"></iframe> --> | |
<!-- <div class="a">cool</div> | |
<div class="b"><iframe width="560" height="315" src="//www.youtube.com/embed/xrMOBKHqqc8?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe> | |
<div class="c"><iframe width="560" height="315" src="//www.youtube.com/embed/xrMOBKHqqc8?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe> --> | |
<form> | |
<input type="email" size="30" title="validate email" name="email" pattern="[a-zA-Z]+@gmail.com" required> | |
<input type="submit" name="submit" disabled> | |
</form> | |
<nav> | |
navbar | |
<aside>aside</aside> | |
</nav> | |
<script type="text/javascript"> | |
let aaa = async function nestedAsy(src) { | |
let script = document.createElement('script'); | |
script.src = src; | |
document.body.append(script); | |
let promis = new Promise(function(resolve, reject) { | |
script.onload = function() { | |
resolve('success'); | |
} | |
}) | |
let result = await promis; | |
return result; | |
console.log("result", result); | |
} | |
aaa('jquery-3.3.1.js').then(res=>console.log("text",res)); | |
</script> | |
<script type="text/javascript"> | |
// function xhrSuccess() { | |
// console.log("arguments",this.arguments); | |
// this.callback.apply(this, this.arguments); | |
// } | |
// function xhrError() { | |
// console.error(this.statusText); | |
// } | |
// function updateProgress (oEvent) { | |
// if (oEvent.lengthComputable) { | |
// var percentComplete = oEvent.loaded / oEvent.total * 100; | |
// console.log( percentComplete,"oEvent.loaded",oEvent.loaded); | |
// // ... | |
// } else { | |
// // Unable to compute progress information since the total size is unknown | |
// } | |
// } | |
// function loadFile(url, callback /*, opt_arg1, opt_arg2, ... */) { | |
// var xhr = new XMLHttpRequest(); | |
// xhr.callback = callback; | |
// xhr.arguments = Array.prototype.slice.call(arguments, 2); | |
// xhr.onload = xhrSuccess; | |
// xhr.addEventListener("progress", updateProgress); | |
// xhr.onerror = xhrError; | |
// xhr.open("GET", url, true); | |
// xhr.send(null); | |
// } | |
// function showMessage(message) { | |
// console.log(message + this); | |
// } | |
// loadFile("jquery-3.3.1.js", showMessage, "New message!\n\n"); | |
// let prose = Promise.resolve(123); | |
// prose.then(res => console.log("text", res)) | |
</script> | |
<script type="text/javascript"> | |
// class ParentClass { | |
// constructor(day, month) { | |
// this.day = day; | |
// this.month = month; | |
// this.daymonth = ''; | |
// } | |
// get display() { | |
// return this.daymonth; | |
// } | |
// set display(both) { | |
// this.daymonth = both; | |
// } | |
// display1(from){ | |
// console.log(arguments,"called from "+ from); | |
// } | |
// } | |
// var pp = new ParentClass('thursday', 10); | |
// console.log("text", pp); | |
// class Child extends ParentClass { | |
// constructor(id, strength) { | |
// let day = 'friday'; | |
// let month = 11; | |
// super(day, month); | |
// this.id = id; | |
// super.display1('super'); | |
// this.strength = strength; | |
// this.display1('this'); | |
// } | |
// } | |
// var dd = new Child(03, 10); | |
// console.log("text", dd); | |
</script> | |
<script type="text/javascript"> | |
// var promis = new Promise(function(res, rej) { | |
// setTimeout(function(argument) { | |
// res(123); | |
// }, 5000); | |
// }) | |
// class Rectangle { | |
// constructor() {} | |
// static logNbSides() { | |
// return 'I have 4 sides'; | |
// } | |
// } | |
// class Square extends Rectangle { | |
// constructor() {} | |
// static logDescription() { | |
// return super.logNbSides() + ' which are all equal'; | |
// } | |
// } | |
// console.log(Square.logDescription()); | |
// console.log(typeof Square); | |
// var promise21 = promis.then(function(res, err) { | |
// console.log(err, "first promise", res); | |
// new Promise(function(res, rej) { | |
// res(456); | |
// }).then(function(res) { | |
// console.log("second", res); | |
// }) | |
// return res; | |
// console.log("afater first promis"); | |
// }).catch(function(err) { | |
// console.log("catch err", err); | |
// }) | |
// console.log(promis); | |
// promise21.then(function(res) { | |
// console.log("third resp", res); | |
// }) | |
</script> | |
<script type="text/javascript"> | |
function promisFn(src) { | |
return new Promise(function(resolve, reject) { | |
let script = document.createElement('script'); | |
script.src = src; | |
script.onload = function() { | |
console.log("script loaded"); | |
resolve(script); | |
} | |
script.onerror = function() { | |
reject(new Error('file missing' + src)); | |
} | |
document.body.append(script); | |
}); | |
} | |
// promisFn('jquery-3.3.1.js') | |
// .then(function(res, err) { | |
// console.log("1st success callback====", res); | |
// return promisFn('jquery-3.3.1.js') | |
// }) | |
// .then(function(res, err) { | |
// console.log("2st success callback====", res); | |
// return promisFn('jquery-3.3.js') | |
// }) | |
// .then(function(res, err) { | |
// console.log("3rd success callback====", res); | |
// return promisFn('jquery-3.3.1.js') | |
// },errorHandler) | |
// .then(function(res, err) { | |
// console.log("4th success callback====", res); | |
// return 'all success' | |
// }) | |
// .catch(function(err) { | |
// console.log("error at ", err); | |
// }) | |
// .finally(function(argument) { | |
// console.log("completed"); | |
// }) | |
// var p1 = promisFn('jquery-3.3.1.js'); | |
// var p2 = promisFn('jquery-3.1.js').catch(errorHandler); | |
// var p3 = promisFn('jquery-3.3.1.js'); | |
// Promise.race([p1, p2, p3]).then((res, err) => { | |
// console.log("Promise.all success", res); | |
// }) | |
// function errorHandler(err) { | |
// console.log("error occured", err); | |
// } | |
</script> | |
<script type="text/javascript"> | |
function greeting(name) { | |
alert('whatsapp ' + name); | |
} | |
function processName(cb) { | |
var name = prompt('whats your name'); | |
cb(name); | |
} | |
// xprocessName(greeting); | |
function loadScript(src, cb) { | |
let script = document.createElement('script'); | |
script.src = src; | |
script.onload = function() { | |
cb(null); | |
} | |
script.onerror = function() { | |
cb(new Error(`Script load error for ${src}`)); | |
} | |
document.body.append(script); | |
console.log("executed"); | |
} | |
// loadScript('jquery-3.3.1.js', function() { | |
// console.log("first script finished"); | |
// loadScript('jquery-3.3.1.js', function() { | |
// console.log("second script finished"); | |
// loadScript('jquery-3.3.js', function(err) { | |
// if (err) { | |
// console.log("text", err); | |
// } | |
// console.log("third script finished"); | |
// loadScript('jquery-3.3.1.js', function() { | |
// console.log("fourth script finished"); | |
// loadScript('jquery-3.3.1.js', function() { | |
// console.log("fifth script finished"); | |
// }); | |
// }); | |
// }); | |
// }); | |
// }); | |
// console.log("im executing cant for jquery-3"); | |
</script> | |
<script type="text/javascript"> | |
function diagonalSum(arr) { | |
let temp = [0, 0]; | |
let n = arr.length; | |
let reduceArr = arr.reduce((a, b) => a.concat(b), []); | |
let rlen = reduceArr.length - 1; | |
let toggle = true; | |
function findDiag(s) { | |
while (rlen >= 0) { | |
toggle = !toggle; | |
if (s === -1) { | |
rlen = rlen - n + 1; | |
temp[1] = temp[1] + reduceArr[rlen]; | |
console.log("temp[1]", temp[1]); | |
nd--; | |
} else { | |
temp[0] = temp[0] + reduceArr[rlen]; | |
console.log("temp[0]", temp[0]); | |
rlen = rlen - n - 1; | |
// ni--; | |
} | |
} | |
} | |
// findDiag(-1); | |
// findDiag(1); | |
console.log(temp, "completed", nd); | |
return temp; | |
} | |
function staircase(n) { | |
let sub = ' '.repeat(n - 1); | |
for (var i = 1; i <= n; i++) { | |
var j = i; | |
let dd = ''; | |
while (j > 0) { | |
dd = dd + '#'; | |
--j; | |
} | |
console.log(sub + dd); | |
sub = sub.substr(1); | |
} | |
} | |
// staircase(5); | |
function diagRec(arr) { | |
let temp = [0, 0]; | |
let n = arr.length; | |
let d = n - 1; | |
for (let i = 0; i < n; i++) { | |
temp[0] = temp[0] + arr[i][i]; | |
temp[1] = temp[1] + arr[i][d]; | |
d--; | |
} | |
console.log("text", temp); | |
return temp; | |
} | |
let arr3 = [ | |
[1, 2, 3], | |
[4, 5, 6], | |
[7, 8, 9] | |
]; | |
let arr4 = [ | |
[1, 2, 3, 6], | |
[4, 5, 6, 5], | |
[7, 8, 9, 4], | |
[7, 8, 9, 3] | |
]; | |
let arr5 = [ | |
[1, 2, -3, 6, 9], | |
[4, 5, 6, 5, 9], | |
[7, 8, -9, 4, 9], | |
[7, -8, 9, 3, 9], | |
[4, 5, 6, 5, -9], | |
]; | |
// diagonalSum(arr);diagRec | |
// diagRec(arr5); | |
//functional intantiation with shared methods | |
// let animalMds = { | |
// bark(en) { | |
// console.log('yessssss', this.name); | |
// this.energy = this.energy + en; | |
// }, | |
// play(pl) { | |
// this.energy -= pl; | |
// } | |
// } | |
// function Animal(name, energy) { | |
// let animal = {}; | |
// animal.name = name; | |
// animal.energy = energy; | |
// animal.play = animalMds.play; | |
// animal.bark = animalMds.bark; | |
// return animal; | |
// } | |
// const leo1 = Animal('Leo', 25); | |
// leo1.play(55); | |
// const parent = { | |
// name: 'arun', | |
// age: 27 | |
// } | |
// const child = Object.create(parent); | |
// child.name = "kumar"; | |
// console.log('chi',child.name); | |
// console.log('chi',child.age); | |
// functional intantiation with shared methods with object.create | |
// const animalMds = { | |
// bark(en) { | |
// console.log('yessssss', this.name); | |
// this.energy = this.energy + en; | |
// }, | |
// play(pl) { | |
// this.energy -= pl; | |
// } | |
// } | |
// function Animal(name, energy) { | |
// let animal = Object.create(animalMds); | |
// animal.name = name; | |
// animal.energy = energy; | |
// return animal; | |
// } | |
// const snoop = Animal('snoop', 25); | |
// snoop.play(10); | |
//prototpal instantiation | |
// function Animal(name, energy) { | |
// let animal = Object.create(Animal.prototype); | |
// animal.name = name; | |
// animal.energy = energy; | |
// return animal; | |
// } | |
// Animal.prototype.bark = function(en) { | |
// console.log('yessssss', this.name); | |
// this.energy = this.energy + en; | |
// } | |
// Animal.prototype.play = function(pl) { | |
// this.energy -= pl; | |
// } | |
// const snoop = Animal('snoop', 25); | |
// snoop.play(55); | |
//pseudolassical instantiation | |
// function Animal(name, energy) { | |
// this.name = name; | |
// this.energy = energy; | |
// } | |
// Animal.prototype.bark = function(en) { | |
// console.log('yessssss', this.name); | |
// this.energy = this.energy + en; | |
// } | |
// Animal.prototype.play = function(pl) { | |
// this.energy -= pl; | |
// } | |
// const snoop = Animal('snoop', 25); //undefined | |
// snoop.play(55); | |
// class | |
// class Animal{ | |
// constructor(name, energy) { | |
// this.name = name; | |
// this.energy = energy; | |
// } | |
// bark(en) { | |
// console.log('yessssss', this.name); | |
// this.energy = this.energy + en; | |
// } | |
// play(pl) { | |
// this.energy -= pl; | |
// } | |
// static sleep(){ | |
// console.log("textslepin"); | |
// } | |
// } | |
//const snoop = new Animal('snoop', 25); | |
//in es5 | |
// function Animal(name, energy) { | |
// this.name = name; | |
// this.energy = energy; | |
// } | |
// Animal.prototype.bark = function(en) { | |
// console.log('yessssss', this.name); | |
// this.energy = this.energy + en; | |
// } | |
// Animal.prototype.play = function(pl) { | |
// this.energy -= pl; | |
// } | |
// Animal.sleep = function() { | |
// console.log("textslepingggg"); | |
// } | |
// const snoop = new Animal('snoop', 25); | |
// snoop.play(55); | |
// promises | |
// var promise = new Promise((resolvefn, rejectfn) => { | |
// setTimeout(() => { | |
// resolvefn('foo'); | |
// }, 3000) | |
// }); | |
// promise.then(resp => { | |
// console.log("text", resp); | |
// }).catch(err => { | |
// console.log("text", err); | |
// }) | |
function asyncc5() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log("before asyncc5"); | |
resolve('asyncc slow'); | |
}, 5000) | |
}) | |
} | |
async function asyncc3() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log("before asyncc3"); | |
resolve('asyncc fast'); | |
}, 3000) | |
}) | |
} | |
// asyncc3().then(res=>console.log("asyncc3", res)); | |
async function f() { | |
let promise = new Promise((resolve, reject) => { | |
setTimeout(() => resolve("done!"), 1000) | |
}); | |
let result = await promise; // wait till the promise resolves (*) | |
console.log("after"); | |
let result1 = await asyncc3(); | |
console.log("inbtw"); | |
console.log("result1", result1); // "done!" | |
console.log("result", result); // "done!" | |
} | |
// f(); | |
// async function callasync() { | |
// var mod5 = await asyncc5(); | |
// console.log("btw slow and fast"); | |
// var mod3 = await asyncc3(); | |
// console.log("after fast"); | |
// console.log("asyncc3 fast", mod3); | |
// console.log("asyncc5 slow", mod5); | |
// } | |
// callasync().then(res=>console.log("completed")); | |
// console.log("typeof", typeof callasync); | |
// function myAsyncFunction(url) { | |
// return new Promise((resolve, reject) => { | |
// const xhr = new XMLHttpRequest(); | |
// xhr.open("GET", url); | |
// xhr.onload = function() { | |
// console.log("onload"); | |
// resolve(xhr.responseText); | |
// } | |
// xhr.onerror = function() { | |
// console.log("onerror"); | |
// reject(xhr.statusText); | |
// } | |
// console.log("beforesend"); | |
// xhr.send(); | |
// console.log("aaftersend"); | |
// }); | |
// } | |
// myAsyncFunction('https://swapi.co/api/people/1').then(res=>{ | |
// console.log("rsponse",res); | |
// }).catch(err=>{ | |
// console.log("err",err); | |
// }) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment