Created
January 11, 2020 19:45
-
-
Save drschwabe/194ae8eca7fa91bcddbf7e819f2f7567 to your computer and use it in GitHub Desktop.
JavaScript type checking
This file contains hidden or 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
const _ = require('underscore') | |
const solarSystem = (...args) => { | |
let planet, asteroids, satellite, spaceJunk, isFake | |
args.forEach(arg => { | |
if(_.isArray(arg)) return asteroids = arg | |
if(_.isObject(arg)) return planet = arg | |
if(_.isString(arg)) return satellite = arg | |
if(_.isNumber(arg)) return spaceJunk = arg | |
if(_.isBoolean(arg)) return isFake = arg | |
}) | |
//proceed to code knowing your arguments are what you expect them to be... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment