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
// take the str parameter being passed and modify it using the | |
// following algorithm. | |
// Replace every letter in the string with the letter following it in the alphabet | |
// (ie.c becomes d, z becomes a).Then capitalize every vowel in this new string (a, e, i, o, u) | |
// and finally return this modified string. | |
function letterChanges(str) { | |
var lowerStart = "a".charCodeAt(0); | |
var upperStart = "A".charCodeAt(0); | |
var letterCount = ("z".charCodeAt(0) - lowerStart) + 1; // 26; |
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
// longest word in sentence, and ignore punctuation. | |
function longestWord(sen) { | |
// would be easier if we had support for unicode character classes, at which point can use \p{P} for punctuation. | |
var punctPattern = /[\!\@\#\$\%\^\&\*\(\)\'\|\"/\\\-\+~`?\<\>\}\{]/g; | |
return sen.replace(punctPattern, '') | |
.split(' ') | |
.reduce(function(p, c, i, a) { | |
var maxLength = p.max; | |
var curLength = c.length; | |
if (curLength >= maxLength) { |
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 factorial(num) { | |
if (num <= 2) return num; | |
return Array.apply(null, Array(num)) | |
.map(function (_, i) { return i + 1; }) | |
.reduce(function(p, c, i, a) { | |
a[i] = (i < 2) ? i+1 : (i + 1) * a[i-1]; | |
return a[i]; | |
}); | |
} |
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
This could have been better served with regex to be honest, but this works too. | |
var Promise = require('bluebird'), | |
request = require('request'), | |
url = require('url'); | |
var servers = ["csd02htp9000", "csd02htp9001"]; | |
function promiseableRequest(server) { | |
return new Promise(function (resolve, reject) { |
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
var Promise = require('bluebird'), | |
request = require('request'), | |
url = require('url'), | |
tests = require('./tests').tests; | |
var environments = { "prod": "", | |
"qa": "qam.", | |
"dev": "localci." | |
}; |
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
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. What is the minimum candies you must give? | |
var box = new CandyBox([2,4,7,8,3,4,6,2]); | |
var count = box.candyCount(); // => [1,2,3,4,1,2,3,1] => 17 |
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
var EnglishDictionary = function (words) { | |
var self = {}; | |
var letterHash = initLeterHash(); | |
// this is efficient enough to get 1mil primes fast. | |
function getPrimes(num) { | |
var primes = [2, 3]; | |
for (var n = 5; primes.length < num; n += 2) { | |
var sqrt = Math.sqrt(n); | |
var isPrime = true; |
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
var Promise = require('bluebird'), | |
request = require('request'), | |
url = require('url'), | |
tests = require('./tests').tests; | |
function promiseableRequest(args) { | |
return new Promise(function(resolve, reject) { | |
var opts = { | |
uri: url.parse(args.url), | |
followRedirect: !!args.redirect |
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
import java.util.HashMap; | |
import java.util.Map.Entry; | |
public class Trie { | |
private HashMap<Character, TNode> nodes = new HashMap<Character, TNode>(); | |
public Trie() {} | |
public void insert(String word) { |
NewerOlder