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"];





Using an array and functions to keep track of train passengers

Step1:



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

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

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 add manual while calling the function

Step3:

Function name called addpessanger



function addpassanger(name, list) {
    if (list.length == 0) {
        list.push(name);
    }
    else {

        for (var i = 0; i < list.length; i++) {

            if (list[i] == undefined) {
                list[i] = name;
                return list;
            }
            else if (i == list.length-1)
            {
                 list.push(name);
                return list;

                }
            }

        }

}


Step4:

addpassanger("faizal", passengerList);
addpassanger("Ashley Smith", passengerList);


output:
console panel :


passengerList;
["Ashley Smith", "Kumar", "Arun"];



Validating to select in sequencial order using angular

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