This file contains hidden or 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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(H) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
let len = H.length; | |
if (len === 1) return 1; | |
let low = 0; | |
let stack = []; | |
let tmp = 0, count=0, countB=0; |
This file contains hidden or 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(A, B) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
let len = A.length; | |
if (len === 1) return 1; | |
let stack = []; | |
// stack.unshift(0); | |
let sum = B.reduce((a,c) => a+c, 0); | |
if (sum === 0 || sum === len) return len; | |
if (sum === 1 === B[len-1]) return len; | |
if (sum === len-1 && B[0] === 0) return len; |
This file contains hidden or 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) { | |
const openBrackets = ['(', '{', '[']; | |
const closeBrackets = [')', '}', ']']; | |
let len = S.length; | |
let stack = []; | |
let counter=0; | |
if (len === 0) { return 1; } | |
if (len % 2 !== 0) { return 0; } | |
This file contains hidden or 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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(A) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
let len = A.length | |
let arr = new Array(len) | |
for(let i=0; i<len;i++) { | |
let idx = A[i] - 1 |
This file contains hidden or 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 jsonToFirebaseJSON(arr) { | |
const result = arr.reduce((acummulator, current, index) => | |
(Object.assign({}, acummulator, {[index]: current})), {}); | |
return JSON.stringify(result); | |
} | |
// index can be replaced with your id/primary key |
This file contains hidden or 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 hasPairOfSum(arr, sum){ | |
var flag; | |
for(let i=0;i<arr.length;i++) { | |
if (flag === arr[i]) { return true; } | |
else if (arr[i] !== sum/2) { continue; } | |
else if(!flag) { flag = arr[i]; } | |
} | |
return false; | |
} |
This file contains hidden or 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
<% _.forEach(env, function(v, k) { %> | |
global.___ENV__['<%= k %>'] = '<%= v %>'; | |
<% }) %> |
This file contains hidden or 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
git fetch origin # Updates origin/master | |
git rebase origin/master # Rebases current branch onto origin/master | |
git rebase -i HEAD~3 # Rebases last 3 commits |
This file contains hidden or 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
# JavaScript Design Pattern | |
## Prototype Inheritance | |
function __extends(Child, Parent) { | |
Child.prototype = new Parent(); | |
} | |
function Person(name) { | |
this.name = name; | |
this.hello = function() { |
This file contains hidden or 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
#!/bin/bash | |
ID_RSA="$OPENSHIFT_DATA_DIR/.ssh/id_rsa" | |
KNOWN_HOSTS="$OPENSHIFT_DATA_DIR/.ssh/known_hosts" | |
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $ID_RSA $1 $2 |