Is it possible to write a function that produces two arrays in Android

Using the JQuery autocomplete I have a function that produces an Array of friends that a user entered in the box.

This array is called selected_Id. However, our project has expanded and along with the 'friends' selection (<--the one that produces the selected_Id array)

we would like to add a 'enemies' function.

It is possible to rewrite that snippet of code to produce 2 separate arrays? If I keep them separate, it will call the getfriends function twice (the getfriends function produces an array of available friends that loads into the jQuery ui that the user gets to choose from).

here is what I have:

  $(function() {
    var available = new Array();
    available = getFriends();
    available = my_friends
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }

    $( "#tags" )
        // don't navigate away from the field on tab when selecting an item
        .bind( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "autocomplete" ).menu.active ) {
                event.preventDefault();
            }
        })
        .autocomplete({
            minLength: 0,
            source: function( request, response ) {
                // delegate back to autocomplete, but extract the last term
                response( $.ui.autocomplete.filter(
                    available, extractLast( request.term ) ) );
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function( event, ui ) {
                var terms = split( this.value );
                // remove the current input
                terms.pop();
                // add the selected item
                //replaced value with label to continue showing the names selected  
                terms.push( ui.item.label);
                //ui.item.valuethis is where my 
                // add placeholder to get the comma-and-space at the end
                terms.push( "" );
                this.value = terms.join( ", " );
                return false;


            }
        });
            $( "button" ).button();
        $( "button" ).click(function() {
        var selected_Text = $( "#tags" ).val();
        var selected_Friends = selected_Text.split(","); 
        //friend name put in the autocomplete box
        var friend_Name = "";
        //selected id of the person in the array 
                var testCount = 0; 
        //i < j --> run through interation once 
        for(var i = 0, j=selected_Friends.length; i<j; i++ )
        {
            friend_Name = selected_Friends[i];
            while (friend_Name[0] == " "){
                friend_Name = friend_Name.substring(1,friend_Name.length);
            }


            for (var k = 0, l = my_friends.length; k<l; k++)
            {

                if (friend_Name == my_friends[k]["label"])
                {
                    selected_Id.push(my_friends[k]["value"])

                    testCount++;

                } else {

                } 
            }
        }

        return false; 


    });
 });

Answers


You could return an object of arrays:

function someFunction() {
    return {
        enemies: [1, 2, 3],
        friends: [4, 5, 6]
    };
}
console.log(someFunction().enemies) //The array of [1,2,3]

By just reading ur question i am saying ... you can return two arrays from a function by just encapsulating those two arrays inside an object and return the object.

function get2arrays() {
    var firstArray = new Array();
    var secondArray = new Array();

    ......

    return { First: firstArray, Second: secondArray };
}

Need Your Help

JavaFX Intellij onAction looks like its not covered in controller

java intellij-idea javafx fxml

I created a simple Fxml application in JavaFX. I added a button with scene builder and an action called btnExit:

MAMP - phpMyAdmin #2002 - Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock'

mysql sockets phpmyadmin mamp

I was working on MAMP phpMyAdmin and everything worked well until i query an ALTER TABLE statement from SQL tab. Operation was too long to end so i decided to refresh my page. From this time, i can...