How to combine two functions into one?

  • 0
    There is an input, it has an input event, there are also two functions, the input event will call some function, if I call one () and two () in this function, it will work incorrectly. If the input contains a string - I need it to call the one () function, if the input contains a number - then let it call two () And of course all this will be displayed on the html document.

    const input = document.querySelector('input');
    input.addEventListener('input', three);
    function one() {
        console.log('Тут будем работать с одним типом данным');
    function two() {
        console.log('Тут будем работать с другим типом данным');
    function three() {
    JavaScript Anonymous, Dec 9, 2019

  • 2 Answers
  • 0
    How can these two functions be made one and hung on the input event

    This can be done, but not necessary. You need to make a third function that will determine which of the cases occurred, call one of the two available functions, receive data from them and display them.
    Myles Mendez

  • 0
    if you want to combine two filters based on the length of the values ​​and the presence of a substring (and keep these filters separately), you need to change these two functions. for me, so you need to pass the parameters (array) that you want to filter (and not receive data inside the function, as now)

    there will be something like the following

    1) got the data using getResponse

    2) called the filtering functions by length, or by the presence of a substring, or both at once (passing data in parameters)
    Eloise Ferrell

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!