0.2.2 • Published 3 years ago

findarg v0.2.2

Weekly downloads
6
License
GPL-3.0
Repository
github
Last release
3 years ago

findarg

En: Finds the value of the argument provides a function for a target result.

Fr: Trouve la valeur de l'argument fournit à une fonction pour un résultat cible.

Experimental ! Does not work on chaotic functions !

Usage

import findarg from 'findarg'

const TARGET_RESULT = 9

let argument = findarg(myFunc, TARGET_RESULT)

console.log(argument) // 3 ± 0.001

function myFunc(arg) {
    return arg**2
}

Arguments

NameTypeRequiredDefinition
funcFunctionyesFunction concerned
targetResultNumberyesTarget result
optionsObjectnoOptions to find the target argument faster.

Options

NametypeDefaultDefinition
keyResultStringnullIn the case where the function returns an object, this key allows to extract the targeted value.
currentArgNumber1Argument whose result is known for the function.
currentResultNumber1Known result returned by the function with the aforementioned argument.
currentSlopeNumber1Slope of the function at the currentArg.
precisionNumber0.001Precision with which the target must be reached.
maxAttempsNumber100Number of tries before abdicating.
isPerfLogBoleanfalseLog the execution time of the resolution.

Return

Argument giving the target result. If you provided the keyResult option, an object is returned :

{
    argument: Number,
    result: {...} //<== Returned by your function
}

How that work

TODO..