JS Ninja #1
by Anupama
JavaScript
console.log((function(n){
try {
if(typeof(n) === "string") {
/* sanitizing input */
n = parseFloat(n);
}
if(!n) {
return "Invalid Input";
} else {
return (function(func, n){
return func(func, n);
})(function(fn, n){
if(n === 1 ) return 1;
else return (n + fn(fn, n-1));
}, n);
}
} catch(e) {
console.log("Something's wrong here!");
}
})(5));