Search This Blog

Saturday, March 18, 2017

Removing the passenger Using an array and functions to keep track of train passengers

 Step1:
Welcome to designer blog, Here we  are going to discuss , how to delete the names in the passenger
list array


Step2:

We  have to initialize two parameters with your own choice...

here we have declared  name and list  here...

list is called passengerList and name which we are going to delete manual while calling the function

var passengerList = ["Babu", "kumar", "Raja"];

Step3:

Function name called deletepessanger 

function deletepassanger(name, list) {
    if (list.length == 0) {
        console.log('list is empty');
    }
    else {
        for (var i = 0; i < list.length; i++) {
           
            if (list[i] == name)
            {
                list[i] = undefined;
                return list;
            }
            else if (i == list.length-1)
            {
                console.log("Passenger not found!");
            }

        }
    }
    return list;
}

Step4 :

var passengerList = ["faizal", "khan", "Basha"];

deletepassanger("faizal", passengerList);

Console output:

passengerList

[undefined, "Khan","Basha"];





No comments:

Post a Comment

Validating to select in sequencial order using angular

    < input type = "checkbox" (change) = "handleSelectTaskItem($event, taskItem)" [checked] = " taskItem . i...