Array-based parameters check I've got a simple JavaScript function that takes multiple types of arguments. Inside the function I'm doing a check on the arguments to determine which way the user called the function:

var build = function() {
    var args = Array.prototype.slice.call(arguments)
    var options = {
        to: {},
        from: {},
        relationship: null
    }

    if (_.isString(args[3]) &amp;&amp; !_.isUuid(args[3]) &amp;&amp; _.isString(args[4])) {
        options.to.type = args[3]
    } else if (_.isString(args[2]) &amp;&amp; !_.isUuid(args[2]) &amp;&amp; _.isString(args[3])) {
        options.to.type = args[2]
    }
}

// called like:
build(client, dataObj, 'relationship', 'type', 'name')
// or
build(client, dataObj, 'relationship', '&lt;uuid&gt;')


This looks messy and isn't really scalable. Is there a more succinct way I can write this (perhaps using .map(), .filter(), or .reduce())?
Define the functions that correspond to a given argument configuration separately:

const processStringNumber = (string, number) =&gt; console.log(number + ' is a number')
const processStringString= (string, string2) =&gt; console.log(string2+ ' is a string')


Put the argument configurations and the corresponding functions in a data structure:

const processingObj = [
  {
    argsTypes: ['string', 'number'],
    process: processStringNumber
  },
  {
    argsTypes: ['string', 'string'],
    process: processStringString
  }
]


Write a helper that does the checks and dispatches the corresponding function:

//Retrieve the types of an array of args (can have different implementations)
const getTypes = (args) =&gt; args.map((arg) =&gt; typeof arg)

//Calls the appropriate function from 'processingObj'
const process = (args, processingObj) =&gt;
  processingObj
    .find((process) =&gt; _.isEqual(process.argsTypes, getTypes(args)))
    .process(...args)


Usage: 

process(["aaa", 1], processingObj) // 1 is a number
process(["aaa", "aaa"], processingObj) // aaa is a string


Here is also an ES5 version (via Babel)