Skip to content

Instantly share code, notes, and snippets.

@IAmAnubhavSaini
IAmAnubhavSaini / Lany2020
Created August 11, 2012 12:08
Language of year 2020
create http server; ip is 127.0.11.12, port is 8850
@IAmAnubhavSaini
IAmAnubhavSaini / tppl
Created July 26, 2013 09:46
The Projects Projects List
original - python - https://github.com/thekarangoel/Projects
forked - ruby ---
...
inspired - C - https://github.com/IAmAnubhavSaini/the-c-projects
forked - c++ ---
...

Note: See how to contribute

=========================================

Numbers

Find PI to the Nth Digit - Enter a number and have the program generate PI up to that many decimal places. Keep a limit to how far the program will go.

Fibonacci Sequence - Enter a number and have the program generate the Fibonacci sequence to that number or to the Nth number.

function palindrome(str) {
var nstr = str.match(/[^\W_]+/gi).map(String.toLowerCase).join('');
console.log(nstr);
return nstr === nstr.split('').reverse().join('');
}
palindrome("0_0 (: /-\ :) 0-0");
function findLongestWord(str) {
return str.split(' ').sort(function(a, b){ return a.length - b.length;}).pop().length;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
findLongestWord("What if we try a super-long word such as otorhinolaryngology") ;
findLongestWord("What is the average airspeed velocity of an unladen swallow");
findLongestWord("Google do a barrel roll");
findLongestWord("May the force be with you");
findLongestWord("The quick brown fox jumped over the lazy dog");
function titleCase(str) {
return str.split(' ').map(String.toLowerCase).map(function(a){ return String.toUpperCase(a[0]).concat(a.substring(1));} ).join(' ');
}
titleCase("I'm a little tea pot");
function largestOfFour(arr) {
myArr = [];
arr.forEach(function(a){ myArr.push(a.sort(function(a, b){ return a-b;}).pop()); });
return myArr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
function end(str, target) {
return str.substr(str.length-target.length, target.length) === target;
}
end("Bastian", "n");
end("Connor", "n");
end("Walking on water and developing software from a specification are easy if both are frozen", "specification");
This is without Javascript Harmony.
function repeat(str, n){
if(n <= 0 || str.length === 0){
return '';
}
if(n === Infinity){
throw new RangeError("I cannot repeat a string Infinity times!");
}
n = Math.floor(+n);
function truncate(str, num) {
if(num >= str.length){
return str;
}
num = num - 3 >= 0 ? num-3 : num;
return str.slice(0, num)+'...';
}
truncate("A-tisket a-tasket A green and yellow basket", 11);