Last active
August 29, 2015 14:04
-
-
Save appikonda/b900535c3c4d66822e39 to your computer and use it in GitHub Desktop.
Type identification and action
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 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
8/10. poor formatting and coding style.