Skip to content

Instantly share code, notes, and snippets.

@appikonda
Last active August 29, 2015 14:04
Show Gist options
  • Save appikonda/b900535c3c4d66822e39 to your computer and use it in GitHub Desktop.
Save appikonda/b900535c3c4d66822e39 to your computer and use it in GitHub Desktop.
Type identification and action
function typer(val) {
// Implement me!
if(typeof(val) === "number" || typeof(val) === "string"){
return val;
}
else if(typeof(val) === "function" )
{
return val();
}
else if(typeof(val) === "object"){
if(val instanceof Object && val instanceof Array ){
return val[(val.length)-1];
}
else
{
return val.lastName;
}
}
}
typer(10);
// 10
typer("hello");
// hello
typer(function() {
console.log("going to return 10...");
return 10;
});
// going to return 10...
// 10
typer([1, 2, 3]);
// 3
typer([1, 2]);
// 2
typer([[1, 2], 2, "asd", 3]);
// 3
typer({ firstName: "Sandeep", lastName: "WTF" });
// WTF
@mohnish
Copy link

mohnish commented Jul 17, 2014

8/10. poor formatting and coding style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment