问:
Is manual foreach loop faster or linq query on collections in the following scenario?
I want to know which approach is faster. I have the following class:

```<code>public class AccountBalance
{
    public long AccountID { get; set; }
    public string AccountNumber { get; set; }

    [NotRequiredForDataTable]
    public IEnumerable<AccountMediaBalance> AccountMediaBalances { get; set; }
}

public class AccountMediaBalance
{
    public long AccountID { get; set; }
    public long MediaID { get; set; }
    public string MediaSerialNumber { get; set; }
    public decimal? CashAmount { get; set; }
    public int FareID { get; set; }
    public bool ShowID { get; set; }
    public bool ShareCash { get; set; }
    public bool ShareToken { get; set; }
    public bool SharePass { get; set; }
    public IEnumerable<Token> Tokens { get; set; }
    public IEnumerable<Pass> Passes { get; set; }
}

public class Token
{
    public long TokenID { get; set; }
    public long AccountID { get; set; }
    public long MediaProductID { get; set; }
    public long MediaID { get; set; }
    public long? ActivateByMediaID { get; set; }
    public string SerialNumber { get; set; }
    public decimal? TransferValue { get; set; }
    public DateTimeOffset CreateTime { get; set; }
    public DateTimeOffset? ActivateTime { get; set; }
    public DateTimeOffset? ExpiryTime { get; set; }
}

public class Pass
{
    public long MediaProductID { get; set; }
    public long AccountID { get; set; }
    public long MediaID { get; set; }
    public int ProductID { get; set; }
    public long? ActivateByMediaID { get; set; }
    public string SerialNumber { get; set; }
    public DateTimeOffset CreateTime { get; set; }
    public DateTimeOffset? ActivateTime { get; set; }
    public DateTimeOffset? ExpiryTime { get; set; }
}
</code>```

I have a list of AccountBalance data as List<AccountBAlance> and I want to transform data in a way that I want to separate AccountMediaBalance collection in one list, All tokens in one list and all passes in a separate list.

There are two approaches for doing this:

```<code>public void SaveAccountBalances(List<AccountBalance> accountBalances)
{
    if (accountBalances != null)
    {
        var mediaBalances = accountBalances.SelectMany(x => x.AccountMediaBalances ??
                            Enumerable.Empty<AccountMediaBalance>()).ToList();

        var tokens = mediaBalances.SelectMany(x => x.Tokens ?? Enumerable.Empty<Token>()).ToList();

        var passes = mediaBalances.SelectMany(x => x.Passes ?? Enumerable.Empty<Pass>()).ToList();
    }
}
</code>```

The other approach would be like following:

```<code>public void SaveAccountBalances(List<AccountBalance> accountBalances)
{
    var mediaBalances = new List<AccountMediaBalance>();
    var tokens = new List<Token>();
    var passes = new List<Pass>();

    if (accountBalances != null)
    {
        foreach (var item in accountBalances)
        {
            mediaBalances.AddRange(item.AccountMediaBalances ?? Enumerable.Empty<AccountMediaBalance>());
        }

        foreach (var item in mediaBalances)
        {
            tokens.AddRange(item.Tokens ?? Enumerable.Empty<Token>());
            passes.AddRange(item.Passes ?? Enumerable.Empty<Pass>());
        }
    }
}
</code>```

Performance is a big concern. Can anyone put me in the right direction and let me know which approach is faster and why?

答: foreach loop uses GetEnumerator directly, while linq creates the query object first and then GetEnumerator. So it is naturally a little bit faster to use foreach loop for a single iteration but it still makes the code look better to use linq.

Body:
I want to know which approach is faster. I have the following class:

public class AccountBalance
{
    public long AccountID { get; set; }
    public string AccountNumber { get; set; }

    [NotRequiredForDataTable]
    public IEnumerable<AccountMediaBalance> AccountMediaBalances { get; set; }
}

public class AccountMediaBalance
{
    public long AccountID { get; set; }
    public long MediaID { get; set; }
    public string MediaSerialNumber { get; set; }
    public decimal? CashAmount { get; set; }
    public int FareID { get; set; }
    public bool ShowID { get; set; }
    public bool ShareCash { get; set; }
    public bool ShareToken { get; set; }
    public bool SharePass { get; set; }
    public IEnumerable<Token> Tokens { get; set; }
    public IEnumerable<Pass> Passes { get; set; }
}

public class Token
{
    public long TokenID { get; set; }
    public long AccountID { get; set; }
    public long MediaProductID { get; set; }
    public long MediaID { get; set; }
    public long? ActivateByMediaID { get; set; }
    public string SerialNumber { get; set; }
    public decimal? TransferValue { get; set; }
    public DateTimeOffset CreateTime { get; set; }
    public DateTimeOffset? ActivateTime { get; set; }
    public DateTimeOffset? ExpiryTime { get; set; }
}

public class Pass
{
    public long MediaProductID { get; set; }
    public long AccountID { get; set; }
    public long MediaID { get; set; }
    public int ProductID { get; set; }
    public long? ActivateByMediaID { get; set; }
    public string SerialNumber { get; set; }
    public DateTimeOffset CreateTime { get; set; }
    public DateTimeOffset? ActivateTime { get; set; }
    public DateTimeOffset? ExpiryTime { get; set; }
}

I have a list of AccountBalance data as List<AccountBAlance> and I want to transform data in a way that I want to separate AccountMediaBalance collection in one list, All tokens in one list and all passes in a separate list.

There are two approaches for doing this:

public void SaveAccountBalances(List<AccountBalance> accountBalances)
{
    if (accountBalances != null)
    {
        var mediaBalances = accountBalances.SelectMany(x => x.AccountMediaBalances ??
                            Enumerable.Empty<AccountMediaBalance>()).ToList();

        var tokens = mediaBalances.SelectMany(x => x.Tokens ?? Enumerable.Empty<Token>()).ToList();

        var passes = mediaBalances.SelectMany(x => x.Passes ?? Enumerable.Empty<Pass>()).ToList();
    }
}

The other approach would be like following:

public void SaveAccountBalances(List<AccountBalance> accountBalances)
{
    var mediaBalances = new List<AccountMediaBalance>();
    var tokens = new List<Token>();
    var passes = new List<Pass>();

    if (accountBalances != null)
    {
        foreach (var item in accountBalances)
        {
            mediaBalances.AddRange(item.AccountMediaBalances ?? Enumerable.Empty<AccountMediaBalance>());
        }

        foreach (var item in mediaBalances)
        {
            tokens.AddRange(item.Tokens ?? Enumerable.Empty<Token>());
            passes.AddRange(item.Passes ?? Enumerable.Empty<Pass>());
        }
    }
}

Performance is a big concern. Can anyone put me in the right direction and let me know which approach is faster and why?


来源: stackexchange

问:
How to get a uniform distribution in a range [r1,r2] in PyTorch?
I want to get a 2-D torch.Tensor with size [a,b] filled with values from a uniform distribution (in range [r1,r2]) in PyTorch.

答:
Please Can you try something like:</p>
```<code>import torch as pt
pt.empty(2,3).uniform_(5,10).type(pt.FloatTensor)
</code>```

ContentLicense: CC BY-SA 4.0

Body:
Please Can you try something like:

import torch as pt
pt.empty(2,3).uniform_(5,10).type(pt.FloatTensor)


问:
how to return the date as dd-FullMonth-yyyy
I have a date field in SharePoint list as mm/dd/yyyy

I want to list it as dd MonthName yyyy

When I use the below function, it return the date with one month added,
for example, if the field date is 1/1/2019 it will be displayed as 1 February 2019 (instead of January, it displays February)

I tried to subtract 1 from monthindex but it didn't work.

```<code>function formatDate(thedate) {
  var monthNames = [
    "January", "February", "March",
    "April", "May", "June", "July",
    "August", "September", "October",
    "November", "December"
  ];
  var diffrentformat = thedate.split(" ")[0];
  var divideddate = diffrentformat.split("-");
  var d = new Date(divideddate[0], divideddate[1], divideddate[2]);
  //var d = new Date(thedate.split[]);
  var day = d.getDate();
  var monthIndex = d.getMonth();
  var year = d.getFullYear();

  return day + ' ' + monthNames[monthIndex] + ' ' + year;
}
</code>```

I expect the output to be dd MonthName yyyy, but I'm getting dd nextMonthName yyyy

答:
Months are zero based (0 = January). You take that into consideration when building up the final string, but not when constructing the date object:</p>

```<code>  new Date(
   /*year*/ divideddate [0] ,
   /*month*/ divideddate [1] - 1,
   /*day*/ divideddate[2]
  );
</code>```

Body:
I have a date field in SharePoint list as mm/dd/yyyy

I want to list it as dd MonthName yyyy

When I use the below function, it return the date with one month added,
for example, if the field date is 1/1/2019 it will be displayed as 1 February 2019 (instead of January, it displays February)

I tried to subtract 1 from monthindex but it didn't work.

function formatDate(thedate) {
  var monthNames = [
    "January", "February", "March",
    "April", "May", "June", "July",
    "August", "September", "October",
    "November", "December"
  ];
  var diffrentformat = thedate.split(" ")[0];
  var divideddate = diffrentformat.split("-");
  var d = new Date(divideddate[0], divideddate[1], divideddate[2]);
  //var d = new Date(thedate.split[]);
  var day = d.getDate();
  var monthIndex = d.getMonth();
  var year = d.getFullYear();

  return day + ' ' + monthNames[monthIndex] + ' ' + year;
}

I expect the output to be dd MonthName yyyy, but I'm getting dd nextMonthName yyyy

Body:
Months are zero based (0 = January). You take that into consideration when building up the final string, but not when constructing the date object:

  new Date(
   /*year*/ divideddate [0] ,
   /*month*/ divideddate [1] - 1,
   /*day*/ divideddate[2]
  );


问:
How to disable Static Files feature in .Net Core API?
I'm migrating my WebAPI to .Net Core, the project contains razor files (.cshtml) which I'll compile at runtime when a method is called and return an HTML file.

Before migrating, all files were accessible to use, after that, I can only access the files under "wwwroot", excluding file types like .cshtml which are always hidden when deployed on Azure.

It's working perfectly on my machine, the issue is when it's deployed live.
I've tried adding and removing app.UseStaticFiles().

I'm using Razorlight to access the razor templates, it's throwing an error saying that the file doesn't exist.

答:
app.UseStaticFiles() only serves the web root(wwwroot) directory. If you need to serve static files from outside the web root directory then you need to set up the StaticFileOptions as shown below.

```<code>public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles(); // For the wwwroot folder

    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
        RequestPath = "/StaticFiles"
    });
}
</code>```

You can then serve files from MyStaticFiles directory like:

http://<server_address>/StaticFiles/MyViews/test.png serves the test.png file

See - Static Files

As mentioned on the comments, ensure that 'MyStaticFiles'(different in your case) exists by navigating to <your-web-app-name>.scm.azurewebsites.net and checking you project hierarchy.

Body:
app.UseStaticFiles() only serves the web root(wwwroot) directory. If you need to serve static files from outside the web root directory then you need to set up the StaticFileOptions as shown below.

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles(); // For the wwwroot folder

    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
        RequestPath = "/StaticFiles"
    });
}

You can then serve files from MyStaticFiles directory like:

http://<server_address>/StaticFiles/MyViews/test.png serves the test.png file

See - Static Files

As mentioned on the comments, ensure that 'MyStaticFiles'(different in your case) exists by navigating to <your-web-app-name>.scm.azurewebsites.net and checking you project hierarchy.


Title: Average a minute-wise time-series dataset monthly with Panda

Body:
I have got a very large minute-wise time series dataset(for 3 months) which is in the following format

datetime,val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,val11,val12
1/06/2017 0:00,0,0,0,0,0,0,0,0,0,0.011,0,0.036
1/06/2017 0:01,0,0,0,0,0,0,0,0,0,0.011,0,0.036
...
1/06/2017 23:59,0,0,0,0,0,0,0,0,0,0.011,0,0.035
2/06/2017 0:00,0,0,0,0,0,0,0,0,0,0.014,0,0.036
2/06/2017 0:01,0,0,0,0,0,0,0,0,0,0.011,0,0.036
...
2/06/2017 23:59,0,0,0,0,0,0,0,0,0,0.011,0,0.035
....
31/08/2017 0:00,0,0.2,0,0,0,0.56,0,0,0,0.014,0,0.036
31/08/2017 0:01,0,0.23,0,0,0,0,0,0,0,0.011,0,0.032
...
31/08/2017 23:59,0,0,0,0,0,0,.55,0,0,0.011,0,0.034

what is the most efficient way of getting the average of each column per each month using panda?
expected output would be

month,val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,val11,val12
06/2017,0,0,0,0,0,0,0,0,0,0.011,0,0.036
07/2017,0,0,0,0,0,0,0,0,0,0.014,0,0.036
08/2017,0,0,0.21,0,0,0,0,0.52,0,0.011,0,0.036

At the moment what I'm doing is read the dataset day by day and then get an accumulated dataset of days and then divide it by the no of days per month. But this very inefficient and take a lot of time.

Body:
Pandas read_csv and to_csv are what you need:

df = pd.read_csv('input.csv', parse_dates=['datetime'])
df.groupby(df.datetime.dt.strftime('%m/%Y')).mean().rename_axis('month').to_csv(out, float_format='%.06f')

With your input data (filtered from ...) it gives:

month,val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,val11,val12
01/2017,0,0.000000,0,0,0,0.000000,0.000000,0,0,0.011000,0,0.035667
02/2017,0,0.000000,0,0,0,0.000000,0.000000,0,0,0.012000,0,0.035667
08/2017,0,0.143333,0,0,0,0.186667,0.183333,0,0,0.012000,0,0.034000


问:
How to programmatically get content type name in Drupal 8
I'm working on Drupal 8. And I want to get content type machine name and label. Here is my code:

```<code>$cont_type = node_type_get_types();
foreach ($cont_type as $key => $value) {
  $label = $value->name;
  $machine_name = $key;
}
</code>```

Here I got an error message : Cannot access protected property Drupal\node\Entity\NodeType::$name

答:
Please use the namespace</p>

```<code>use Drupal\node\Entity\Node;
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm working on Drupal 8. And I want to get content type machine name and label. Here is my code:

$cont_type = node_type_get_types();
foreach ($cont_type as $key => $value) {
  $label = $value->name;
  $machine_name = $key;
}

Here I got an error message : Cannot access protected property Drupal\node\Entity\NodeType::$name

Body:
Please use the namespace

use Drupal\node\Entity\Node;


问:
Chained sections in ConstrainedLayout
I want to have a layout with a few "sections", each section containing heading and some TextViews, EdiTexts, etc.

I want the sections evenly distributed on the screen, and they can't overlap. So it seems chain is the way to go.

But the problem I always have is how to group some elements in the chain? I don't want to have individual items in each section evenely spaced, I want to have the whole sections evenly spaced. Is it somehow possible? Or will I have to use nested layouts, which pretty much breaks the whole idea of ConstraintLayout?

答: I was able to solve it with ConstraintLayout 2.0's Flow helper.

Title: Chained sections in ConstrainedLayout


问:
How to remove string except followed by certain characters with regular expression?
I want to remove ab from a string if ab is not followed by x or y.

For example, if the string is 123ab456, the result should be 123456.

If the string is 123abx456, the result should be123abx456.

How could I use regex to do so?

答:
Here's a way using re.sub with a negative lookahead:

```<code>re.sub(r'ab(?![xy])', '', s)
</code>```

```<code>s = '123ab456'
re.sub(r'ab(?![xy])', '', s)
# '123456'

s = '123abx456'
re.sub(r'ab(?![xy])', '', s)
# '123abx456'
</code>```

 Details

ab(?![xy])

ab matches the characters ab literally (case sensitive)

Negative Lookahead (?![xy])

Match a single character present in the list [xy]

xy matches a single character in the list xy (case sensitive)

Body:
Here's a way using re.sub with a negative lookahead:

re.sub(r'ab(?![xy])', '', s)

s = '123ab456'
re.sub(r'ab(?![xy])', '', s)
# '123456'

s = '123abx456'
re.sub(r'ab(?![xy])', '', s)
# '123abx456'

 Details

ab(?![xy])

ab matches the characters ab literally (case sensitive)

Negative Lookahead (?![xy])

Match a single character present in the list [xy]

xy matches a single character in the list xy (case sensitive)


问:
Eventbrite API and Pagination
When querying the Eventbrite API the results are paginated, however, the API documentation doesn't describe how to request page 2 and beyond.

I have tried adding various parameters to the request including "page", "paging", and "pagination" but none of them work and page 1 is always returned.

Can anyone tell me how to do this properly?

Cheers,
-Josh.

Title: Eventbrite API and Pagination

Body: events/{{event_id}}/attendees/?token={{token}}&page=2


问:
Decorator pattern for a Customer class
Suppose I have a Customer class. A customer can have multiple kinds of loyalty points. For one promotion, the customer may be collecting Rewards. In another, the customer may be collecting Miles. And there is no fixed number of kinds of loyalty points that the Customer is built for. I am sure this is a common use case. Is the decorator pattern a good fit given below sample code?

```<code>    public interface ICustomer
    {
        void Display();
    }

    public class SimpleCustomer : ICustomer
    {
        public void Display()
        {
            Console.WriteLine("I am simple customer");
        }
    }

    public abstract class CustomerDecorator : ICustomer
    {
        protected ICustomer customer;

        public CustomerDecorator(ICustomer customer)
        {
            this.customer = customer ?? throw new ArgumentNullException("customer");
        }

        public abstract void Display();
    }

    public class RewardsDecorator : CustomerDecorator
    {
        private int rewards;
        public RewardsDecorator(ICustomer customer, int rewards) : base(customer)
        {
            this.rewards = rewards;
        }

        public override void Display()
        {
            Console.WriteLine("Now I have " + rewards.ToString() + " rewards");
        }
    }

    public class MilesDecorator : CustomerDecorator
    {
        private int miles;
        public MilesDecorator(ICustomer customer, int miles) : base(customer)
        {
            this.miles = miles;
        }

        public override void Display()
        {
            Console.WriteLine("Now I have " + miles.ToString() + " miles");
        }
    }
</code>```

答:
I do not think that Decorator is the pattern you are looking for.

Besides, your code does not seem to be an implementation of the Decorator pattern. You do not add any functionality to the only function. You just override it. But adding to the existing function is what the Decorator pattern is all about.

My approach would be state / strategy pattern. There are different kinds of rewards. And a customer has one or more of them. These rewards may share a common interface and provide different implementations. The customer (or a subclass or compound object RewardedCustomer) should hold a list or map of these rewards.

Title: Decorator pattern for a Customer class

Body:
Suppose I have a Customer class. A customer can have multiple kinds of loyalty points. For one promotion, the customer may be collecting Rewards. In another, the customer may be collecting Miles. And there is no fixed number of kinds of loyalty points that the Customer is built for. I am sure this is a common use case. Is the decorator pattern a good fit given below sample code?

    public interface ICustomer
    {
        void Display();
    }

    public class SimpleCustomer : ICustomer
    {
        public void Display()
        {
            Console.WriteLine("I am simple customer");
        }
    }

    public abstract class CustomerDecorator : ICustomer
    {
        protected ICustomer customer;

        public CustomerDecorator(ICustomer customer)
        {
            this.customer = customer ?? throw new ArgumentNullException("customer");
        }

        public abstract void Display();
    }

    public class RewardsDecorator : CustomerDecorator
    {
        private int rewards;
        public RewardsDecorator(ICustomer customer, int rewards) : base(customer)
        {
            this.rewards = rewards;
        }

        public override void Display()
        {
            Console.WriteLine("Now I have " + rewards.ToString() + " rewards");
        }
    }

    public class MilesDecorator : CustomerDecorator
    {
        private int miles;
        public MilesDecorator(ICustomer customer, int miles) : base(customer)
        {
            this.miles = miles;
        }

        public override void Display()
        {
            Console.WriteLine("Now I have " + miles.ToString() + " miles");
        }
    }


问:
How to extract string from JSON object in protractor
I am not able to extract string from JSON object in protractor in webstorm. I want value of statusCode i.e :200, The code I've tried for this mentioned below...

CODE IS :

```<code>console.log('body is :' + JSON.stringify(body));

var jsonResponse = JSON.stringify(response);

console.log('---------response is: '+ jsonResponse);

var statusResponse = jsonResponse.getString("statusCode");

console.log('---- statusResponse is :'+ statusResponse.toString());
</code>```

OUTPUT IS:

```<code>body is :{"oBody":{"payLoad":{"sLoginId":"HDB_TW_DSA@softcell.com","iInstId":4019,"sFirstName":"PRIYANKA","sLastName":"MADGUNDI","sEmail":"priyanka@softcell.com","sEmpId":"HDB18458","sMobile":"8237276692","bActive":true,"aRoles":["DSA"],"aDealers":[{"id":"TW423684019","iInstId":4019,"iDlrId":"42368","sDlrName":"GODSPEED MOTORCYCLE PVT LTD","iBranchId":1278,"sBranchName":"HYDERABAD-SF","sProduct":"TW","bActive":true},{"oStatus":{"iStatus":200,"sStatus":"OK"}}
</code>```

---------response is:

```<code>{"statusCode":200,"body":{"oBody":{"payLoad":{"sLoginId":"HDB_TW_DSA@softcell.com","iInstId":4019,"sFirstName":"PRIYANKA","sLastName":"MADGUNDI","sEmail":"priyanka@softcell.com","sEmpId":"HDB18458","sMobile":"8237276692","bActive":true,"aRoles":["DSA"],"aDealers","path":"/gonogo-api/atm/login-web-v3","href":"https://ssg.serviceurl.in/login-web-v3"},"method":"POST","headers":{"Postman-Token":"7aad048f-f8ad-4765-a0b8-be3b3a485ab6","cache-control":"no-cache","Content-Type":"application/json","accept":"application/json","content-length":380}}}
</code>```

答:
Try the below option

```<code>var res= JSON.parse(response);
console.log(res[0].statusCode);
</code>```

Hope it helps you

Body:
I am not able to extract string from JSON object in protractor in webstorm. I want value of statusCode i.e :200, The code I've tried for this mentioned below...

CODE IS :

console.log('body is :' + JSON.stringify(body));

var jsonResponse = JSON.stringify(response);

console.log('---------response is: '+ jsonResponse);

var statusResponse = jsonResponse.getString("statusCode");

console.log('---- statusResponse is :'+ statusResponse.toString());

OUTPUT IS:

body is :{"oBody":{"payLoad":{"sLoginId":"HDB_TW_DSA@softcell.com","iInstId":4019,"sFirstName":"PRIYANKA","sLastName":"MADGUNDI","sEmail":"priyanka@softcell.com","sEmpId":"HDB18458","sMobile":"8237276692","bActive":true,"aRoles":["DSA"],"aDealers":[{"id":"TW423684019","iInstId":4019,"iDlrId":"42368","sDlrName":"GODSPEED MOTORCYCLE PVT LTD","iBranchId":1278,"sBranchName":"HYDERABAD-SF","sProduct":"TW","bActive":true},{"oStatus":{"iStatus":200,"sStatus":"OK"}}

---------response is:

{"statusCode":200,"body":{"oBody":{"payLoad":{"sLoginId":"HDB_TW_DSA@softcell.com","iInstId":4019,"sFirstName":"PRIYANKA","sLastName":"MADGUNDI","sEmail":"priyanka@softcell.com","sEmpId":"HDB18458","sMobile":"8237276692","bActive":true,"aRoles":["DSA"],"aDealers","path":"/gonogo-api/atm/login-web-v3","href":"https://ssg.serviceurl.in/login-web-v3"},"method":"POST","headers":{"Postman-Token":"7aad048f-f8ad-4765-a0b8-be3b3a485ab6","cache-control":"no-cache","Content-Type":"application/json","accept":"application/json","content-length":380}}}

Body:
Try the below option

var res= JSON.parse(response);
console.log(res[0].statusCode);

Hope it helps you


问:
Not getting value from scope, getting error : Cannot set property 'value' of undefined
```<code>var app = angular.module("Main", []);

app.controller("MainCtrl", [ function ($scope) {
    $scope.value = 545
}]);`
var app = angular.module("Main", []);

app.controller("MainCtrl", [ function ($scope) {
    $scope.value = 545
}]);
</code>```

答:
You DI is wrong, you need to add $scope both as argument and list into the array.

```<code>app.controller("MainCtrl", ["$scope", function ($scope) {
    $scope.value = 545
}]);
</code>```

Or you have to do this:

```<code>app.controller("MainCtrl", function ($scope) {
    $scope.value = 545
});
</code>```

The first one is recommanded because the second one works only for unminified code.

Body:
You DI is wrong, you need to add $scope both as argument and list into the array.

app.controller("MainCtrl", ["$scope", function ($scope) {
    $scope.value = 545
}]);

Or you have to do this:

app.controller("MainCtrl", function ($scope) {
    $scope.value = 545
});

The first one is recommanded because the second one works only for unminified code.


问:
How to select json array from mysql?
I have such json array in MySql

```<code>[{  "to": "0xACA7A6819ebc5135D1Be4D9952C1219ad6a3182f",
  "from": "0xF6b023e576E86067e9604ee31215873E4495C06f"}]
</code>```

I need simple action, just get all array!

```<code> // This not work
 SELECT deposit FROM users WHERE wallet = 0X...
</code>```

答:
Try using 'like' keyword.

ex :

```<code>"SELECT deposit FROM users WHERE wallet like '%0xACA7A6819ebc5135D1Be4D9952C1219ad6a3182f%';
</code>```

statement above should able to select all the record where wallet column contain string above.

Note : add the percent sign indicate it's a wildcard search

Title: How to select json array from mysql?

Body:
I have such json array in MySql

[{  "to": "0xACA7A6819ebc5135D1Be4D9952C1219ad6a3182f",
  "from": "0xF6b023e576E86067e9604ee31215873E4495C06f"}]

I need simple action, just get all array!

 // This not work
 SELECT deposit FROM users WHERE wallet = 0X...

Body:
Try using 'like' keyword.

ex :

"SELECT deposit FROM users WHERE wallet like '%0xACA7A6819ebc5135D1Be4D9952C1219ad6a3182f%';

statement above should able to select all the record where wallet column contain string above.

Note : add the percent sign indicate it's a wildcard search


问:
errmsg" : "No host described in new configuration 1 for replica set rs0 maps to this node", Why I am getting this message?
I am getting this message every time I do rs.initiate() :

No host described in new configuration 1 for replica set rs0 maps to this node

This is how my /etc/hosts/ file looks on both the replica set servers.

Server 1 and server 2 "hosts" file

127.0.0.1 localhost

  aa.bb.cc.dd DataMongo1

  ee.ff.gg.hh DataMongo2

Server 1-mongod.conf file

bind-ip aa.bb.cc.dd

Server 2 -mongod.conf file

bind-ip ee.ff.gg.hh

changed server1 hostname to DataMongo1 and server2 to DataMongo2

$hostname DataMongo1

Port 27071 is uncommented on both servers

ReplicaSet config file:

cfg= {

  _id:"rs0",

  members:[{_id:0,host:"DataMongo1:27071"},{_id:1,host:"DataMongo2:27071"}]}

Please help me with this issue.

答: Looks like the port is wrong. The default port of MongoDB is 27017, not 27071.</p>


问:
How to append one dimensional arrays at axis=1
I am acquiring samples of dimensions (2,1). I am trying to stack them in columns.

I have tried the following:

```<code># My initial state
state=np.array([2,3])
trajectory =state

# the following generate the next samples
class Buck:
  """ The following code simulates a Buck converter """
  def __init__(self,state,control):
    self.control=control
    self.state=state

  def Next_State(self):
    L, C = 1.0, 1.0
    R, G = 1.0, 1.0
    delta = 0.001

    Q = np.array([[-1.0/L,0.0],[0.0,1.0/C]])
    A = Q*np.matmul(Q,np.array([[R,1.0],[1.0,-G]]))

    next_state = state + delta*np.matmul(A,state)

    return next_state

# Here I am appending the new samples to trajectory

for i in range(100000):
  state=Buck.Next_State(state)
  np.append(trajectory,state,axis=1)
</code>```

It is saying that I can not convert (2,) dimensional array to (2,2) dimensional array.

答:
state needs to be a column vector for the multiplication to work.  It is currently just a 1D array.  You can either add in a singleton dimension, or make state a 2D array of a single row and transpose:

```<code>state=np.array([2,3])[:,None]
</code>```

OR

```<code>state=np.array([[2,3]]).T
</code>```

However, if it is your task to append all of the states to your trajectory, then you need to change two more things:

You need to make a fresh copy of the state to trajectory.  Right now, you are only providing a slice to it so modifying trajectory will also modify state.

np.append outputs the newly appended array.  You are not capturing the output of the method so you are actually not appending to anything.

Therefore:

```<code># My initial state
import numpy as np

state=np.array([2,3])[:,None] # Change
trajectory =state.copy() # Change

# the following generate the next samples
class Buck:
  """ The following code simulates a Buck converter """
  def __init__(self,state,control):
    self.control=control
    self.state=state

  def Next_State(self):
    L, C = 1.0, 1.0
    R, G = 1.0, 1.0
    delta = 0.001

    Q = np.array([[-1.0/L,0.0],[0.0,1.0/C]])
    A = Q*np.matmul(Q,np.array([[R,1.0],[1.0,-G]]))

    next_state = state + delta*np.matmul(A,state)

    return next_state

# Here I am appending the new samples to trajectory

for i in range(100000):
  state=Buck.Next_State(state)
  trajectory = np.append(trajectory,state,axis=1) # Change
</code>```

Body:
I am acquiring samples of dimensions (2,1). I am trying to stack them in columns.

I have tried the following:

# My initial state
state=np.array([2,3])
trajectory =state

# the following generate the next samples
class Buck:
  """ The following code simulates a Buck converter """
  def __init__(self,state,control):
    self.control=control
    self.state=state

  def Next_State(self):
    L, C = 1.0, 1.0
    R, G = 1.0, 1.0
    delta = 0.001

    Q = np.array([[-1.0/L,0.0],[0.0,1.0/C]])
    A = Q*np.matmul(Q,np.array([[R,1.0],[1.0,-G]]))

    next_state = state + delta*np.matmul(A,state)

    return next_state

# Here I am appending the new samples to trajectory

for i in range(100000):
  state=Buck.Next_State(state)
  np.append(trajectory,state,axis=1)

It is saying that I can not convert (2,) dimensional array to (2,2) dimensional array.

Body:
state needs to be a column vector for the multiplication to work.  It is currently just a 1D array.  You can either add in a singleton dimension, or make state a 2D array of a single row and transpose:

state=np.array([2,3])[:,None]

OR

state=np.array([[2,3]]).T

However, if it is your task to append all of the states to your trajectory, then you need to change two more things:

You need to make a fresh copy of the state to trajectory.  Right now, you are only providing a slice to it so modifying trajectory will also modify state.

np.append outputs the newly appended array.  You are not capturing the output of the method so you are actually not appending to anything.

Therefore:

# My initial state
import numpy as np

state=np.array([2,3])[:,None] # Change
trajectory =state.copy() # Change

# the following generate the next samples
class Buck:
  """ The following code simulates a Buck converter """
  def __init__(self,state,control):
    self.control=control
    self.state=state

  def Next_State(self):
    L, C = 1.0, 1.0
    R, G = 1.0, 1.0
    delta = 0.001

    Q = np.array([[-1.0/L,0.0],[0.0,1.0/C]])
    A = Q*np.matmul(Q,np.array([[R,1.0],[1.0,-G]]))

    next_state = state + delta*np.matmul(A,state)

    return next_state

# Here I am appending the new samples to trajectory

for i in range(100000):
  state=Buck.Next_State(state)
  trajectory = np.append(trajectory,state,axis=1) # Change


问:
customizing bootstrap form-control on select option
I'm using bootstrap's form-control class to keep a consistent style between my form input and those that requires a select option. However using bootstrap's form-control on select elements gives it the ugly drop-down button in firefox.

What I'd like to achieve is this

However looking through the css part I have no way of identifying which part it is that I should override as there does not seem to be a css specifying the drop-down arrow's decoration.

This is how the current code looks like

```<code><div class="form-group row">
    <label for="industry" class="">Industry :</label>
    <select name="industry" class="form-control">
        <option value="" disabled selected>Select Industry</option>
        <option value="financial-service">Financial Services</option>
        <option value="healthcare-lifescience">Healthcare & Life Science</option>
        <option value="communications">Communications</option>
    </select>
</div>
</code>```

答:
You can implement Chosen(jQuery plugin for select) in it. It has lots of features on it and also you can design it easily.

Link: https://harvesthq.github.io/chosen/

In your code :

```<code>  <link
    rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css"
  />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>
  <div class="form-group">
    <label for="industry" class="">Industry :</label>
    <select name="industry" id="industry" class="form-control chosen-select">
      <option value="" disabled selected>Select Industry</option>
      <option value="financial-service">Financial Services</option>
      <option value="healthcare-lifescience">Healthcare & Life Science</option>
      <option value="communications">Communications</option>
    </select>
  </div>
  <script>
    $("#industry").chosen();
  </script>
</code>```

Body:
I'm using bootstrap's form-control class to keep a consistent style between my form input and those that requires a select option. However using bootstrap's form-control on select elements gives it the ugly drop-down button in firefox.

What I'd like to achieve is this

However looking through the css part I have no way of identifying which part it is that I should override as there does not seem to be a css specifying the drop-down arrow's decoration.

This is how the current code looks like

    Industry :
    <select name="industry" class="form-control">
        <option value="" disabled selected>Select Industry</option>
        <option value="financial-service">Financial Services</option>
        <option value="healthcare-lifescience">Healthcare & Life Science</option>
        <option value="communications">Communications</option>
    </select>

Body:
You can implement Chosen(jQuery plugin for select) in it. It has lots of features on it and also you can design it easily.

Link: https://harvesthq.github.io/chosen/

In your code :

  <link
    rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css"
  />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>
  <div class="form-group">
    <label for="industry" class="">Industry :</label>
    <select name="industry" id="industry" class="form-control chosen-select">
      <option value="" disabled selected>Select Industry</option>
      <option value="financial-service">Financial Services</option>
      <option value="healthcare-lifescience">Healthcare & Life Science</option>
      <option value="communications">Communications</option>
    </select>
  </div>
  <script>
    $("#industry").chosen();
  </script>


问:
How to share my webpage to twitter in a card
I have done as the guide in Optimize Tweets with Cards, but it does not work like put my image and description in a card to share to others.

I want to share my webpage in a card for twitter.

```<code><meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="summary" />
<meta name="twitter:creator" content="summary" />
<meta name="twitter:image" content="https://stackoverflow.com/questions/56339282/how-to-share-my-webpage-to-twitter-in-a-card/are_6b65b534.jpg" />
<meta name="twitter:description"   content="@ViewBag.Description" />
</code>```

As I put the guide code in my webpage, I still just get a url when I share my webpage.

Thanks for your help.

答:
Please add the property attributes like:

```<code><meta property="og:url" content="http://bits.blogs.nytimes.com/2011/12/08/a-twitter-for-my-sister/" />
<meta property="og:title" content="A Twitter for My Sister" />
<meta property="og:description" content="In the early days, Twitter grew so quickly that it was almost impossible to add new features because engineers spent their time trying to keep the rocket ship from stalling." />
<meta property="og:image" content="http://graphics8.nytimes.com/images/2011/12/08/technology/bits-newtwitter/bits-newtwitter-tmagArticle.jpg" />
</code>```

Please the example from twitter Optimize Tweets with Cards. Also try to add full path of image like the example and full content in description tag.

Body:
I have done as the guide in Optimize Tweets with Cards, but it does not work like put my image and description in a card to share to others.

I want to share my webpage in a card for twitter.

<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="summary" />
<meta name="twitter:creator" content="summary" />
<meta name="twitter:image" content="https://stackoverflow.com/questions/56339282/how-to-share-my-webpage-to-twitter-in-a-card/are_6b65b534.jpg" />
<meta name="twitter:description"   content="@ViewBag.Description" />

As I put the guide code in my webpage, I still just get a url when I share my webpage.

Thanks for your help.

Body:
Please add the property attributes like:

<meta property="og:url" content="http://bits.blogs.nytimes.com/2011/12/08/a-twitter-for-my-sister/" />
<meta property="og:title" content="A Twitter for My Sister" />
<meta property="og:description" content="In the early days, Twitter grew so quickly that it was almost impossible to add new features because engineers spent their time trying to keep the rocket ship from stalling." />
<meta property="og:image" content="http://graphics8.nytimes.com/images/2011/12/08/technology/bits-newtwitter/bits-newtwitter-tmagArticle.jpg" />

Please the example from twitter Optimize Tweets with Cards. Also try to add full path of image like the example and full content in description tag.


问:
How To make 2 or more tables From one JSON data
I am working on creating dynamic HTML table from JSON Data, I have already created the table dynamically but now I have to Change it with new Requirement

What I am doing

I have array of objects from which i am creating the table and spiting the table into four columns by dividing the length of JSON to 4

My table is rendering perfectly into 4 columns

What I am trying to Do

I want to show only 5 Rows in a single go then reloads the div and render the next five rows in same dive and so on until all data gets render

Currently I have 68 total data so i am populating it as 17 rows of 4 columns

Now on one go when page lodes I want to show 5 rows then after 5 seconds Next 5 rows in same div

In simple terms I want to split my JSON data into part of 5-5 rows and show only 5 rows at once then next five after 5 seconds

Spiting the Table into Four Columns I have done already,now just want to Show only five rows at a time

I am lacking with idea or approach how to do this, How can i divide my JSON in five-five rows and show them at each time interval of 5 seconds

What I am have done

var tableValue = [{
  "Item Name": "MANCHOW  V SOUP",
  "SellingPrice": 100
}, {
  "Item Name": "MANCHOW NV SOUP ",
  "SellingPrice": 125
}, {
  "Item Name": "CEASER SALAD V",
  "SellingPrice": 175
}, {
  "Item Name": "CEASER SALAD NV",
  "SellingPrice": 230
}, {
  "Item Name": "GAMBUS REBOZADAS",
  "SellingPrice": 350
}, {
  "Item Name": "PANCO FISH FINGER",
  "SellingPrice": 270
}, {
  "Item Name": "MUSHROOM DUPLEX",
  "SellingPrice": 160
}, {
  "Item Name": "FRENCH FRIES",
  "SellingPrice": 99
}, {
  "Item Name": "HONEY GARLIC PRAWN",
  "SellingPrice": 350
}, {
  "Item Name": "CHICKEN MANCHURIAN",
  "SellingPrice": 180
}, {
  "Item Name": "MUSHROOM CHILLY",
  "SellingPrice": 120
}, {
  "Item Name": "SALT N PEPPER BABY CORN",
  "SellingPrice": 120
}, {
  "Item Name": "SOUTHERN STYLE CHICKEN",
  "SellingPrice": 210
}, {
  "Item Name": "PANEER NAGGETS",
  "SellingPrice": 210
}, {
  "Item Name": "HARA BHARA KEBAB",
  "SellingPrice": 160
}, {
  "Item Name": "CHICKEN TIKKA",
  "SellingPrice": 210
}, {
  "Item Name": "KALMI KEBAB",
  "SellingPrice": 250
}, {
  "Item Name": "PIZZA MARGARITTA",
  "SellingPrice": 200
}, {
  "Item Name": "PIZZA VEG FARMHOUSE",
  "SellingPrice": 200
}, {
  "Item Name": "BBQ CHICKEN PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "CHICKEN TIKKA PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "PESTO SAUCE",
  "SellingPrice": 175
}, {
  "Item Name": "ARABIATA",
  "SellingPrice": 160
}, {
  "Item Name": "PINK SAUCE",
  "SellingPrice": 160
}, {
  "Item Name": "GARBANZO BEAN SALAD",
  "SellingPrice": 90
}, {
  "Item Name": "MASALA PAPAD",
  "SellingPrice": 50
}, {
  "Item Name": "PEANUT MASALA",
  "SellingPrice": 60
}, {
  "Item Name": "GAJAR KA HALWA",
  "SellingPrice": 90
}, {
  "Item Name": "WATERMELON MARTINI",
  "SellingPrice": 281
}, {
  "Item Name": "Kiwi martini",
  "SellingPrice": 281
}, {
  "Item Name": " Apple gin",
  "SellingPrice": 225
}, {
  "Item Name": "Cucumber  cooler ",
  "SellingPrice": 281
}, {
  "Item Name": "Martini",
  "SellingPrice": 225
}, {
  "Item Name": "Pink lady",
  "SellingPrice": 225
}, {
  "Item Name": " Bloody marry",
  "SellingPrice": 281
}, {
  "Item Name": "Cosmopolitan",
  "SellingPrice": 281
}, {
  "Item Name": "Sex on the beach",
  "SellingPrice": 281
}, {
  "Item Name": "Bull frog",
  "SellingPrice": 506
}, {
  "Item Name": "Long  island iced tea ",
  "SellingPrice": 393
}, {
  "Item Name": "Pinacolada",
  "SellingPrice": 225
}, {
  "Item Name": "Daiquiri",
  "SellingPrice": 225
}, {
  "Item Name": "Mojito ",
  "SellingPrice": 281
}, {
  "Item Name": "Whisky sour",
  "SellingPrice": 281
}, {
  "Item Name": "Hot toddy",
  "SellingPrice": 225
}, {
  "Item Name": "Margarita",
  "SellingPrice": 337
}, {
  "Item Name": "Tequila sunrise",
  "SellingPrice": 337
}, {
  "Item Name": "Red sangria",
  "SellingPrice": 225
}, {
  "Item Name": "White sangria",
  "SellingPrice": 247
}, {
  "Item Name": "Rose sangria",
  "SellingPrice": 247
}, {
  "Item Name": "By chance special ",
  "SellingPrice": 168
}, {
  "Item Name": "Made in heaven",
  "SellingPrice": 168
}, {
  "Item Name": "Strawberry delight",
  "SellingPrice": 168
}, {
  "Item Name": "DRAGON",
  "SellingPrice": 168
}, {
  "Item Name": "Mangochil ",
  "SellingPrice": 168
}, {
  "Item Name": "Cucumber cola",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mojito",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mary",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin pinacolada",
  "SellingPrice": 168
}, {
  "Item Name": "CORONA",
  "SellingPrice": 438
}, {
  "Item Name": "CRAFT BEERS",
  "SellingPrice": 337
}, {
  "Item Name": "BIRA WHITE 330",
  "SellingPrice": 157
}, {
  "Item Name": "BIRA BLONDE 330",
  "SellingPrice": 135
}, {
  "Item Name": "BIRA STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER PREMIUM 330",
  "SellingPrice": 123
}, {
  "Item Name": "KINGFISHER PREMIUM 650",
  "SellingPrice": 202
}, {
  "Item Name": "KINGFISHER STRONG 330",
  "SellingPrice": 135
}, {
  "Item Name": "KINGFISHER STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER ULTRA 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA 650",
  "SellingPrice": 281
}, {
  "Item Name": "KINGFISHER ULTRA MAX 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA MAX 650",
  "SellingPrice": 281
}, {
  "Item Name": "BUDWIESER 330",
  "SellingPrice": 146
}, {
  "Item Name": "BUDWIESER 650",
  "SellingPrice": 270
}, {
  "Item Name": "BUDWIESER MAGNUM 330",
  "SellingPrice": 168
}, {
  "Item Name": "BUDWIESER MAGNUM 650",
  "SellingPrice": 281
}, {
  "Item Name": "TUBORG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG 650",
  "SellingPrice": 191
}, {
  "Item Name": "TUBORG STRONG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "CRANBERRY ",
  "SellingPrice": 157
}, {
  "Item Name": "ORANGE",
  "SellingPrice": 157
}, {
  "Item Name": "JAMICAN",
  "SellingPrice": 157
}, {
  "Item Name": "BLACK BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "BLUE BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "MOET CHANDON",
  "SellingPrice": 7875
}, {
  "Item Name": "SULA BRUT",
  "SellingPrice": 1687
}, {
  "Item Name": "MATEUS ROSE",
  "SellingPrice": 2137
}, {
  "Item Name": "HARDYS SIRAZ CABERNET 750",
  "SellingPrice": 1890
}, {
  "Item Name": "HARDYS SIRAZ CABERNET BY GLASS",
  "SellingPrice": 382
}, {
  "Item Name": "JACOB CREEK SIRAZ 750",
  "SellingPrice": 1800
}, {
  "Item Name": "JACOB CREEK SIRAZ BY GLASS",
  "SellingPrice": 360
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC 750",
  "SellingPrice": 990
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC BY GLASS",
  "SellingPrice": 202
}, {
  "Item Name": "SULA CHENIN BLANC 750 ",
  "SellingPrice": 1293
}, {
  "Item Name": "SULA CHENIN BLANC BY GLASS",
  "SellingPrice": 258
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC 750",
  "SellingPrice": 1125
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON 750",
  "SellingPrice": 1125
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "SULA SATORI MERLOT 750",
  "SellingPrice": 1237
}, {
  "Item Name": "SULA SATORI MERLOT BY GLASS",
  "SellingPrice": 247
}, {
  "Item Name": "GROVERS LA RESERVE 750",
  "SellingPrice": 1800
}, {
  "Item Name": "GROVERS LA RESERVE 100",
  "SellingPrice": 360
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 700 ",
  "SellingPrice": 9225
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 30",
  "SellingPrice": 405
}, {
  "Item Name": "TALISKER 750",
  "SellingPrice": 8775
}, {
  "Item Name": "TALISKER 30",
  "SellingPrice": 360
}, {
  "Item Name": "GLENNLIVET 750",
  "SellingPrice": 8887
}, {
  "Item Name": "GLENNLIVET 30",
  "SellingPrice": 360
}, {
  "Item Name": "THE SINGLETON 750",
  "SellingPrice": 7942
}, {
  "Item Name": "THE SINGLETON 30",
  "SellingPrice": 326
}, {
  "Item Name": "AMRUT FUSION 750",
  "SellingPrice": 5062
}, {
  "Item Name": "AMRUT FUSION 30",
  "SellingPrice": 202
}, {
  "Item Name": "JACK DANIELS 750",
  "SellingPrice": 7312
}, {
  "Item Name": "JACK DANIELS 30",
  "SellingPrice": 292
}, {
  "Item Name": "JIM BEAM WHITE 750",
  "SellingPrice": 4095
}, {
  "Item Name": "JIM BEAM WHITE 30",
  "SellingPrice": 168
}, {
  "Item Name": "JAMESON 750",
  "SellingPrice": 4950
}, {
  "Item Name": "JAMESON 30",
  "SellingPrice": 202
}, {
  "Item Name": "JW BLACK LABEL 750",
  "SellingPrice": 8212
}, {
  "Item Name": "JW BLACK LABEL 200",
  "SellingPrice": 2925
}, {
  "Item Name": "JW BLACK LABEL 30",
  "SellingPrice": 337
}, {
  "Item Name": "JW RED LABEL 200",
  "SellingPrice": 1158
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 750",
  "SellingPrice": 4545
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 30",
  "SellingPrice": 180
}, {
  "Item Name": "BLACK \u0026 WHITE 375",
  "SellingPrice": 1575
}, {
  "Item Name": "BLACK \u0026 WHITE 180",
  "SellingPrice": 787
}, {
  "Item Name": "BLACK \u0026 WHITE 60",
  "SellingPrice": 258
}, {
  "Item Name": "BLACK \u0026 WHITE 30",
  "SellingPrice": 135
}, {
  "Item Name": "100 PIPERS 180",
  "SellingPrice": 787
}, {
  "Item Name": "100 PIPERS 60",
  "SellingPrice": 258
}, {
  "Item Name": "100 PIPERS 30",
  "SellingPrice": 135
}, {
  "Item Name": "VAT 69 180",
  "SellingPrice": 675
}, {
  "Item Name": "VAT 69 60",
  "SellingPrice": 225
}, {
  "Item Name": "VAT 69 30",
  "SellingPrice": 112
}, {
  "Item Name": "TEACHERS HIGHLAND 180",
  "SellingPrice": 787
}, {
  "Item Name": "TEACHERS HIGHLAND 60",
  "SellingPrice": 258
}, {
  "Item Name": "TEACHERS HIGHLAND 30",
  "SellingPrice": 135
}, {
  "Item Name": "TEACHERS 50 60",
  "SellingPrice": 393
}, {
  "Item Name": "TEACHERS 50 30",
  "SellingPrice": 202
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 180",
  "SellingPrice": 1215
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 30",
  "SellingPrice": 213
}, {
  "Item Name": "BLACK DOG 8 YEARS 180",
  "SellingPrice": 731
}, {
  "Item Name": "BLACK DOG 8 YEARS 60",
  "SellingPrice": 247
}, {
  "Item Name": "BLACK DOG 8 YEARS 30",
  "SellingPrice": 123
}, {
  "Item Name": "BLENDERS PRIDE 750",
  "SellingPrice": 2283
}, {
  "Item Name": "BLENDERS PRIDE 375",
  "SellingPrice": 1147
}, {
  "Item Name": "BLENDERS PRIDE 180",
  "SellingPrice": 573
}, {
  "Item Name": "BLENDERS PRIDE 60",
  "SellingPrice": 191
}, {
  "Item Name": "BLENDERS PRIDE 30",
  "SellingPrice": 90
}, {
  "Item Name": "SIGNATURE 180",
  "SellingPrice": 450
}, {
  "Item Name": "SIGNATURE 60",
  "SellingPrice": 168
}, {
  "Item Name": "SIGNATURE 30",
  "SellingPrice": 90
}, {
  "Item Name": "GREY GOOSE 750",
  "SellingPrice": 8190
}, {
  "Item Name": "GREY GOOSE 30",
  "SellingPrice": 326
}, {
  "Item Name": "BELVEDERE 700",
  "SellingPrice": 8122
}, {
  "Item Name": "BELVEDERE 30",
  "SellingPrice": 360
}, {
  "Item Name": "CIROC 750",
  "SellingPrice": 7425
}, {
  "Item Name": "CIROC 30",
  "SellingPrice": 303
}, {
  "Item Name": "ABSOLUT 750",
  "SellingPrice": 4556
}, {
  "Item Name": "ABSOLUT 30",
  "SellingPrice": 191
}, {
  "Item Name": "SMIRNOFF RED 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF RED 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF RED30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF ORANGE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMINOFF ORANGE30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF GREEN APPLE30",
  "SellingPrice": 101
}, {
  "Item Name": "BOMBAY SAPHIRE 750",
  "SellingPrice": 4725
}, {
  "Item Name": "BOMBAY SAPHIRE 30",
  "SellingPrice": 191
}, {
  "Item Name": "BLUE RIBBAND 750",
  "SellingPrice": 877
}, {
  "Item Name": "BLUE RIBBAND 60",
  "SellingPrice": 78
}, {
  "Item Name": "BACCARDI WHITE 750",
  "SellingPrice": 2418
}, {
  "Item Name": "BACCARDI WHITE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI WHITE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI WHITE 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI LEMON 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI LEMON 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI ORANGE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI BLACK 180",
  "SellingPrice": 393
}, {
  "Item Name": "BACCARDI BLACK 30",
  "SellingPrice": 67
}, {
  "Item Name": "BACCARDI GOLD 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI GOLD30",
  "SellingPrice": 101
}, {
  "Item Name": "OLD MONK 180",
  "SellingPrice": 225
}, {
  "Item Name": "OLD MONK 90",
  "SellingPrice": 168
}, {
  "Item Name": "OLD MONK 60",
  "SellingPrice": 90
}, {
  "Item Name": "OLD MONK 30 ",
  "SellingPrice": 45
}, {
  "Item Name": "DON ANGEL 750",
  "SellingPrice": 4668
}, {
  "Item Name": "DON ANGEL 30",
  "SellingPrice": 191
}, {
  "Item Name": "SAUZA SILVER 700",
  "SellingPrice": 6153
}, {
  "Item Name": "SAUZA SILVER 30",
  "SellingPrice": 270
}, {
  "Item Name": "JAGERBOMB",
  "SellingPrice": 506
}, {
  "Item Name": "KAMAKAZI",
  "SellingPrice": 168
}, {
  "Item Name": "JAGERMASTER",
  "SellingPrice": 303
}, {
  "Item Name": "COINTTRAEU",
  "SellingPrice": 303
}, {
  "Item Name": "SAMBUCA",
  "SellingPrice": 258
}, {
  "Item Name": "KHALUA",
  "SellingPrice": 168
}, {
  "Item Name": "MARTINI BLANCO",
  "SellingPrice": 90
}, {
  "Item Name": "MARTINI ROSSO",
  "SellingPrice": 90
}, {
  "Item Name": "HENESSY VS 700",
  "SellingPrice": 7875
}, {
  "Item Name": "HENESSY VS 30",
  "SellingPrice": 348
}, {
  "Item Name": "MORPHEUS 750",
  "SellingPrice": 2182
}, {
  "Item Name": "MORPHEUS 180",
  "SellingPrice": 540
}, {
  "Item Name": "MORPHEUS 60",
  "SellingPrice": 191
}, {
  "Item Name": "MORPHEUS 30",
  "SellingPrice": 101
}, {
  "Item Name": "MANSION HOUSE 180",
  "SellingPrice": 292
}, {
  "Item Name": "MANSION HOUSE 90",
  "SellingPrice": 168
}, {
  "Item Name": "MANSION HOUSE 60",
  "SellingPrice": 90
}, {
  "Item Name": "MC BRANDY 60",
  "SellingPrice": 90
}, {
  "Item Name": "RED BULL ",
  "SellingPrice": 157
}, {
  "Item Name": "COKE",
  "SellingPrice": 45
}, {
  "Item Name": "SPRITE",
  "SellingPrice": 45
}, {
  "Item Name": "SODA",
  "SellingPrice": 33
}, {
  "Item Name": "DIET COKE",
  "SellingPrice": 56
}, {
  "Item Name": "TONIC WATER",
  "SellingPrice": 67
}, {
  "Item Name": "GINGER ALE",
  "SellingPrice": 67
}, {
  "Item Name": "LIME SODA",
  "SellingPrice": 45
}, {
  "Item Name": "LIME WATER",
  "SellingPrice": 45
}, {
  "Item Name": "PACKEGED WATER 1L",
  "SellingPrice": 39
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}]

myFun();
window.setInterval(showRows, 5000);
showRows();

function myFun() {
  addTable(tableValue);
}

function showRows() {
  $(".hidden:lt(10)").removeClass("hidden");
}

function addTable(tableValue) {
  var $tbl = $("
", {
      "class": "table"
    }),

    $tb = $("
"),
    $trh = $("
");

  var split = Math.round(tableValue.length / 4);
  for (i = 0; i < split; i++) {
    $tr = $("
", {
      class: "hidden"
    });
    for (j = 0; j < 4; j++) {
      $.each(tableValue[split * j + i], function(key, value) {

        $("", {
          "class": "text-left color" + (j + 1)
        }).html(value).appendTo($tr);
      });
    }
    $tr.appendTo($tb);
  }
  $tbl.append($tb);
  $("#DisplayTable").html($tbl);
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>tbody>tr>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
  white-space: nowrap;
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}</code>```

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">

```

Edit
I have tried @Void's solution but that is not removing the hidden class,when I inspect the element then there is no class applied to tr it is showing as class=""

答:
Instead of creating the rows after every 5 seconds, you can create the rows in one go and hide them all using a class .hidden. Then every 5 seconds make first 5 hidden rows visible.

```<code>$(".hidden:lt(5)").removeClass("hidden");
</code>```

Call this every 5 seconds.

var tableValue = [{
    "Item Name": "MANCHOW  V SOUP",
    "SellingPrice": 100
  },
  {
    "Item Name": "MANCHOW NV SOUP ",
    "SellingPrice": 125
  },
  {
    "Item Name": "CEASER SALAD V",
    "SellingPrice": 175
  },
  {
    "Item Name": "CEASER SALAD NV",
    "SellingPrice": 230
  },
  {
    "Item Name": "GAMBUS REBOZADAS",
    "SellingPrice": 350
  },
  {
    "Item Name": "PANCO FISH FINGER",
    "SellingPrice": 270
  },
  {
    "Item Name": "MUSHROOM DUPLEX",
    "SellingPrice": 160
  },
  {
    "Item Name": "FRENCH FRIES",
    "SellingPrice": 99
  },
  {
    "Item Name": "HONEY GARLIC PRAWN",
    "SellingPrice": 350
  },
  {
    "Item Name": "CHICKEN MANCHURIAN",
    "SellingPrice": 180
  },
  {
    "Item Name": "MUSHROOM CHILLY",
    "SellingPrice": 120
  },
  {
    "Item Name": "SALT N PEPPER BABY CORN",
    "SellingPrice": 120
  },
  {
    "Item Name": "SOUTHERN STYLE CHICKEN",
    "SellingPrice": 210
  },
  {
    "Item Name": "PANEER NAGGETS",
    "SellingPrice": 210
  },
  {
    "Item Name": "HARA BHARA KEBAB",
    "SellingPrice": 160
  },
  {
    "Item Name": "CHICKEN TIKKA",
    "SellingPrice": 210
  },
  {
    "Item Name": "KALMI KEBAB",
    "SellingPrice": 250
  },
  {
    "Item Name": "PIZZA MARGARITTA",
    "SellingPrice": 200
  },
  {
    "Item Name": "PIZZA VEG FARMHOUSE",
    "SellingPrice": 200
  },
  {
    "Item Name": "BBQ CHICKEN PIZZA",
    "SellingPrice": 225
  },
  {
    "Item Name": "CHICKEN TIKKA PIZZA",
    "SellingPrice": 225
  },
  {
    "Item Name": "PESTO SAUCE",
    "SellingPrice": 175
  },
  {
    "Item Name": "ARABIATA",
    "SellingPrice": 160
  },
  {
    "Item Name": "PINK SAUCE",
    "SellingPrice": 160
  },
  {
    "Item Name": "GARBANZO BEAN SALAD",
    "SellingPrice": 90
  },
  {
    "Item Name": "MASALA PAPAD",
    "SellingPrice": 50
  },
  {
    "Item Name": "PEANUT MASALA",
    "SellingPrice": 60
  },
  {
    "Item Name": "GAJAR KA HALWA",
    "SellingPrice": 90
  },
  {
    "Item Name": "WATERMELON MARTINI",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Kiwi martini",
    "SellingPrice": 281.25
  },
  {
    "Item Name": " Apple gin",
    "SellingPrice": 225
  },
  {
    "Item Name": "Cucumber  cooler ",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Martini",
    "SellingPrice": 225
  },
  {
    "Item Name": "Pink lady",
    "SellingPrice": 225
  },
  {
    "Item Name": " Bloody marry",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Cosmopolitan",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Sex on the beach",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Bull frog",
    "SellingPrice": 506.25
  },
  {
    "Item Name": "Long  island iced tea ",
    "SellingPrice": 393.75
  },
  {
    "Item Name": "Pinacolada",
    "SellingPrice": 225
  },
  {
    "Item Name": "Daiquiri",
    "SellingPrice": 225
  },
  {
    "Item Name": "Mojito ",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Whisky sour",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Hot toddy",
    "SellingPrice": 225
  },
  {
    "Item Name": "Margarita",
    "SellingPrice": 337.5
  },
  {
    "Item Name": "Tequila sunrise",
    "SellingPrice": 337.5
  },
  {
    "Item Name": "Red sangria",
    "SellingPrice": 225
  },
  {
    "Item Name": "White sangria",
    "SellingPrice": 247.5
  },
  {
    "Item Name": "Rose sangria",
    "SellingPrice": 247.5
  },
  {
    "Item Name": "By chance special ",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Made in heaven",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Strawberry delight",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "DRAGON",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Mangochil ",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Cucumber cola",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Virgin mojito",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Virgin mary",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Virgin pinacolada",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "CORONA",
    "SellingPrice": 438.75
  },
  {
    "Item Name": "CRAFT BEERS",
    "SellingPrice": 337.5
  },
  {
    "Item Name": "BIRA WHITE 330",
    "SellingPrice": 157.5
  },
  {
    "Item Name": "BIRA BLONDE 330",
    "SellingPrice": 135
  },
  {
    "Item Name": "BIRA STRONG 650",
    "SellingPrice": 213.75
  },
  {
    "Item Name": "KINGFISHER PREMIUM 330",
    "SellingPrice": 123.75
  },
  {
    "Item Name": "KINGFISHER PREMIUM 650",
    "SellingPrice": 202.5
  },
  {
    "Item Name": "KINGFISHER PREMIUM 330",
    "SellingPrice": 123.75
  },
  {
    "Item Name": "KINGFISHER PREMIUM 650",
    "SellingPrice": 202.5
  },
  {
    "Item Name": "TESTING ITEM",
    "SellingPrice": 22
  }
]

myFun();
window.setInterval(showRows, 5000);
showRows();
function myFun() {
  addTable(tableValue);
}

function showRows(){
  $(".hidden:lt(5)").removeClass("hidden");
}

function addTable(tableValue) {
  var $tbl = $("
", {
      "class": "table"
    }),

    $tb = $("
"),
    $trh = $("
");

  var split = Math.round(tableValue.length / 4);
  for (i = 0; i < split; i++) {
    $tr = $("
", {class: "hidden"});
    for (j = 0; j < 4; j++) {
      $.each(tableValue[split * j + i], function(key, value) {

        $("", {
          "class": "text-left color" + (j + 1)
        }).html(value).appendTo($tr);
      });
    }
    $tr.appendTo($tb);
  }
  $tbl.append($tb);
  $("#DisplayTable").html($tbl);
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>tbody>tr>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
  white-space: nowrap;
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}

.hidden {
  display: none;
}</code>```

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">

```

Body:
I am working on creating dynamic HTML table from JSON Data, I have already created the table dynamically but now I have to Change it with new Requirement

What I am doing

I have array of objects from which i am creating the table and spiting the table into four columns by dividing the length of JSON to 4

My table is rendering perfectly into 4 columns

What I am trying to Do

I want to show only 5 Rows in a single go then reloads the div and render the next five rows in same dive and so on until all data gets render

Currently I have 68 total data so i am populating it as 17 rows of 4 columns

Now on one go when page lodes I want to show 5 rows then after 5 seconds Next 5 rows in same div

In simple terms I want to split my JSON data into part of 5-5 rows and show only 5 rows at once then next five after 5 seconds

Spiting the Table into Four Columns I have done already,now just want to Show only five rows at a time

I am lacking with idea or approach how to do this, How can i divide my JSON in five-five rows and show them at each time interval of 5 seconds

What I am have done

var tableValue = [{
  "Item Name": "MANCHOW  V SOUP",
  "SellingPrice": 100
}, {
  "Item Name": "MANCHOW NV SOUP ",
  "SellingPrice": 125
}, {
  "Item Name": "CEASER SALAD V",
  "SellingPrice": 175
}, {
  "Item Name": "CEASER SALAD NV",
  "SellingPrice": 230
}, {
  "Item Name": "GAMBUS REBOZADAS",
  "SellingPrice": 350
}, {
  "Item Name": "PANCO FISH FINGER",
  "SellingPrice": 270
}, {
  "Item Name": "MUSHROOM DUPLEX",
  "SellingPrice": 160
}, {
  "Item Name": "FRENCH FRIES",
  "SellingPrice": 99
}, {
  "Item Name": "HONEY GARLIC PRAWN",
  "SellingPrice": 350
}, {
  "Item Name": "CHICKEN MANCHURIAN",
  "SellingPrice": 180
}, {
  "Item Name": "MUSHROOM CHILLY",
  "SellingPrice": 120
}, {
  "Item Name": "SALT N PEPPER BABY CORN",
  "SellingPrice": 120
}, {
  "Item Name": "SOUTHERN STYLE CHICKEN",
  "SellingPrice": 210
}, {
  "Item Name": "PANEER NAGGETS",
  "SellingPrice": 210
}, {
  "Item Name": "HARA BHARA KEBAB",
  "SellingPrice": 160
}, {
  "Item Name": "CHICKEN TIKKA",
  "SellingPrice": 210
}, {
  "Item Name": "KALMI KEBAB",
  "SellingPrice": 250
}, {
  "Item Name": "PIZZA MARGARITTA",
  "SellingPrice": 200
}, {
  "Item Name": "PIZZA VEG FARMHOUSE",
  "SellingPrice": 200
}, {
  "Item Name": "BBQ CHICKEN PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "CHICKEN TIKKA PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "PESTO SAUCE",
  "SellingPrice": 175
}, {
  "Item Name": "ARABIATA",
  "SellingPrice": 160
}, {
  "Item Name": "PINK SAUCE",
  "SellingPrice": 160
}, {
  "Item Name": "GARBANZO BEAN SALAD",
  "SellingPrice": 90
}, {
  "Item Name": "MASALA PAPAD",
  "SellingPrice": 50
}, {
  "Item Name": "PEANUT MASALA",
  "SellingPrice": 60
}, {
  "Item Name": "GAJAR KA HALWA",
  "SellingPrice": 90
}, {
  "Item Name": "WATERMELON MARTINI",
  "SellingPrice": 281
}, {
  "Item Name": "Kiwi martini",
  "SellingPrice": 281
}, {
  "Item Name": " Apple gin",
  "SellingPrice": 225
}, {
  "Item Name": "Cucumber  cooler ",
  "SellingPrice": 281
}, {
  "Item Name": "Martini",
  "SellingPrice": 225
}, {
  "Item Name": "Pink lady",
  "SellingPrice": 225
}, {
  "Item Name": " Bloody marry",
  "SellingPrice": 281
}, {
  "Item Name": "Cosmopolitan",
  "SellingPrice": 281
}, {
  "Item Name": "Sex on the beach",
  "SellingPrice": 281
}, {
  "Item Name": "Bull frog",
  "SellingPrice": 506
}, {
  "Item Name": "Long  island iced tea ",
  "SellingPrice": 393
}, {
  "Item Name": "Pinacolada",
  "SellingPrice": 225
}, {
  "Item Name": "Daiquiri",
  "SellingPrice": 225
}, {
  "Item Name": "Mojito ",
  "SellingPrice": 281
}, {
  "Item Name": "Whisky sour",
  "SellingPrice": 281
}, {
  "Item Name": "Hot toddy",
  "SellingPrice": 225
}, {
  "Item Name": "Margarita",
  "SellingPrice": 337
}, {
  "Item Name": "Tequila sunrise",
  "SellingPrice": 337
}, {
  "Item Name": "Red sangria",
  "SellingPrice": 225
}, {
  "Item Name": "White sangria",
  "SellingPrice": 247
}, {
  "Item Name": "Rose sangria",
  "SellingPrice": 247
}, {
  "Item Name": "By chance special ",
  "SellingPrice": 168
}, {
  "Item Name": "Made in heaven",
  "SellingPrice": 168
}, {
  "Item Name": "Strawberry delight",
  "SellingPrice": 168
}, {
  "Item Name": "DRAGON",
  "SellingPrice": 168
}, {
  "Item Name": "Mangochil ",
  "SellingPrice": 168
}, {
  "Item Name": "Cucumber cola",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mojito",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mary",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin pinacolada",
  "SellingPrice": 168
}, {
  "Item Name": "CORONA",
  "SellingPrice": 438
}, {
  "Item Name": "CRAFT BEERS",
  "SellingPrice": 337
}, {
  "Item Name": "BIRA WHITE 330",
  "SellingPrice": 157
}, {
  "Item Name": "BIRA BLONDE 330",
  "SellingPrice": 135
}, {
  "Item Name": "BIRA STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER PREMIUM 330",
  "SellingPrice": 123
}, {
  "Item Name": "KINGFISHER PREMIUM 650",
  "SellingPrice": 202
}, {
  "Item Name": "KINGFISHER STRONG 330",
  "SellingPrice": 135
}, {
  "Item Name": "KINGFISHER STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER ULTRA 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA 650",
  "SellingPrice": 281
}, {
  "Item Name": "KINGFISHER ULTRA MAX 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA MAX 650",
  "SellingPrice": 281
}, {
  "Item Name": "BUDWIESER 330",
  "SellingPrice": 146
}, {
  "Item Name": "BUDWIESER 650",
  "SellingPrice": 270
}, {
  "Item Name": "BUDWIESER MAGNUM 330",
  "SellingPrice": 168
}, {
  "Item Name": "BUDWIESER MAGNUM 650",
  "SellingPrice": 281
}, {
  "Item Name": "TUBORG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG 650",
  "SellingPrice": 191
}, {
  "Item Name": "TUBORG STRONG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "CRANBERRY ",
  "SellingPrice": 157
}, {
  "Item Name": "ORANGE",
  "SellingPrice": 157
}, {
  "Item Name": "JAMICAN",
  "SellingPrice": 157
}, {
  "Item Name": "BLACK BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "BLUE BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "MOET CHANDON",
  "SellingPrice": 7875
}, {
  "Item Name": "SULA BRUT",
  "SellingPrice": 1687
}, {
  "Item Name": "MATEUS ROSE",
  "SellingPrice": 2137
}, {
  "Item Name": "HARDYS SIRAZ CABERNET 750",
  "SellingPrice": 1890
}, {
  "Item Name": "HARDYS SIRAZ CABERNET BY GLASS",
  "SellingPrice": 382
}, {
  "Item Name": "JACOB CREEK SIRAZ 750",
  "SellingPrice": 1800
}, {
  "Item Name": "JACOB CREEK SIRAZ BY GLASS",
  "SellingPrice": 360
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC 750",
  "SellingPrice": 990
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC BY GLASS",
  "SellingPrice": 202
}, {
  "Item Name": "SULA CHENIN BLANC 750 ",
  "SellingPrice": 1293
}, {
  "Item Name": "SULA CHENIN BLANC BY GLASS",
  "SellingPrice": 258
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC 750",
  "SellingPrice": 1125
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON 750",
  "SellingPrice": 1125
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "SULA SATORI MERLOT 750",
  "SellingPrice": 1237
}, {
  "Item Name": "SULA SATORI MERLOT BY GLASS",
  "SellingPrice": 247
}, {
  "Item Name": "GROVERS LA RESERVE 750",
  "SellingPrice": 1800
}, {
  "Item Name": "GROVERS LA RESERVE 100",
  "SellingPrice": 360
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 700 ",
  "SellingPrice": 9225
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 30",
  "SellingPrice": 405
}, {
  "Item Name": "TALISKER 750",
  "SellingPrice": 8775
}, {
  "Item Name": "TALISKER 30",
  "SellingPrice": 360
}, {
  "Item Name": "GLENNLIVET 750",
  "SellingPrice": 8887
}, {
  "Item Name": "GLENNLIVET 30",
  "SellingPrice": 360
}, {
  "Item Name": "THE SINGLETON 750",
  "SellingPrice": 7942
}, {
  "Item Name": "THE SINGLETON 30",
  "SellingPrice": 326
}, {
  "Item Name": "AMRUT FUSION 750",
  "SellingPrice": 5062
}, {
  "Item Name": "AMRUT FUSION 30",
  "SellingPrice": 202
}, {
  "Item Name": "JACK DANIELS 750",
  "SellingPrice": 7312
}, {
  "Item Name": "JACK DANIELS 30",
  "SellingPrice": 292
}, {
  "Item Name": "JIM BEAM WHITE 750",
  "SellingPrice": 4095
}, {
  "Item Name": "JIM BEAM WHITE 30",
  "SellingPrice": 168
}, {
  "Item Name": "JAMESON 750",
  "SellingPrice": 4950
}, {
  "Item Name": "JAMESON 30",
  "SellingPrice": 202
}, {
  "Item Name": "JW BLACK LABEL 750",
  "SellingPrice": 8212
}, {
  "Item Name": "JW BLACK LABEL 200",
  "SellingPrice": 2925
}, {
  "Item Name": "JW BLACK LABEL 30",
  "SellingPrice": 337
}, {
  "Item Name": "JW RED LABEL 200",
  "SellingPrice": 1158
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 750",
  "SellingPrice": 4545
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 30",
  "SellingPrice": 180
}, {
  "Item Name": "BLACK \u0026 WHITE 375",
  "SellingPrice": 1575
}, {
  "Item Name": "BLACK \u0026 WHITE 180",
  "SellingPrice": 787
}, {
  "Item Name": "BLACK \u0026 WHITE 60",
  "SellingPrice": 258
}, {
  "Item Name": "BLACK \u0026 WHITE 30",
  "SellingPrice": 135
}, {
  "Item Name": "100 PIPERS 180",
  "SellingPrice": 787
}, {
  "Item Name": "100 PIPERS 60",
  "SellingPrice": 258
}, {
  "Item Name": "100 PIPERS 30",
  "SellingPrice": 135
}, {
  "Item Name": "VAT 69 180",
  "SellingPrice": 675
}, {
  "Item Name": "VAT 69 60",
  "SellingPrice": 225
}, {
  "Item Name": "VAT 69 30",
  "SellingPrice": 112
}, {
  "Item Name": "TEACHERS HIGHLAND 180",
  "SellingPrice": 787
}, {
  "Item Name": "TEACHERS HIGHLAND 60",
  "SellingPrice": 258
}, {
  "Item Name": "TEACHERS HIGHLAND 30",
  "SellingPrice": 135
}, {
  "Item Name": "TEACHERS 50 60",
  "SellingPrice": 393
}, {
  "Item Name": "TEACHERS 50 30",
  "SellingPrice": 202
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 180",
  "SellingPrice": 1215
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 30",
  "SellingPrice": 213
}, {
  "Item Name": "BLACK DOG 8 YEARS 180",
  "SellingPrice": 731
}, {
  "Item Name": "BLACK DOG 8 YEARS 60",
  "SellingPrice": 247
}, {
  "Item Name": "BLACK DOG 8 YEARS 30",
  "SellingPrice": 123
}, {
  "Item Name": "BLENDERS PRIDE 750",
  "SellingPrice": 2283
}, {
  "Item Name": "BLENDERS PRIDE 375",
  "SellingPrice": 1147
}, {
  "Item Name": "BLENDERS PRIDE 180",
  "SellingPrice": 573
}, {
  "Item Name": "BLENDERS PRIDE 60",
  "SellingPrice": 191
}, {
  "Item Name": "BLENDERS PRIDE 30",
  "SellingPrice": 90
}, {
  "Item Name": "SIGNATURE 180",
  "SellingPrice": 450
}, {
  "Item Name": "SIGNATURE 60",
  "SellingPrice": 168
}, {
  "Item Name": "SIGNATURE 30",
  "SellingPrice": 90
}, {
  "Item Name": "GREY GOOSE 750",
  "SellingPrice": 8190
}, {
  "Item Name": "GREY GOOSE 30",
  "SellingPrice": 326
}, {
  "Item Name": "BELVEDERE 700",
  "SellingPrice": 8122
}, {
  "Item Name": "BELVEDERE 30",
  "SellingPrice": 360
}, {
  "Item Name": "CIROC 750",
  "SellingPrice": 7425
}, {
  "Item Name": "CIROC 30",
  "SellingPrice": 303
}, {
  "Item Name": "ABSOLUT 750",
  "SellingPrice": 4556
}, {
  "Item Name": "ABSOLUT 30",
  "SellingPrice": 191
}, {
  "Item Name": "SMIRNOFF RED 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF RED 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF RED30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF ORANGE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMINOFF ORANGE30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF GREEN APPLE30",
  "SellingPrice": 101
}, {
  "Item Name": "BOMBAY SAPHIRE 750",
  "SellingPrice": 4725
}, {
  "Item Name": "BOMBAY SAPHIRE 30",
  "SellingPrice": 191
}, {
  "Item Name": "BLUE RIBBAND 750",
  "SellingPrice": 877
}, {
  "Item Name": "BLUE RIBBAND 60",
  "SellingPrice": 78
}, {
  "Item Name": "BACCARDI WHITE 750",
  "SellingPrice": 2418
}, {
  "Item Name": "BACCARDI WHITE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI WHITE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI WHITE 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI LEMON 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI LEMON 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI ORANGE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI BLACK 180",
  "SellingPrice": 393
}, {
  "Item Name": "BACCARDI BLACK 30",
  "SellingPrice": 67
}, {
  "Item Name": "BACCARDI GOLD 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI GOLD30",
  "SellingPrice": 101
}, {
  "Item Name": "OLD MONK 180",
  "SellingPrice": 225
}, {
  "Item Name": "OLD MONK 90",
  "SellingPrice": 168
}, {
  "Item Name": "OLD MONK 60",
  "SellingPrice": 90
}, {
  "Item Name": "OLD MONK 30 ",
  "SellingPrice": 45
}, {
  "Item Name": "DON ANGEL 750",
  "SellingPrice": 4668
}, {
  "Item Name": "DON ANGEL 30",
  "SellingPrice": 191
}, {
  "Item Name": "SAUZA SILVER 700",
  "SellingPrice": 6153
}, {
  "Item Name": "SAUZA SILVER 30",
  "SellingPrice": 270
}, {
  "Item Name": "JAGERBOMB",
  "SellingPrice": 506
}, {
  "Item Name": "KAMAKAZI",
  "SellingPrice": 168
}, {
  "Item Name": "JAGERMASTER",
  "SellingPrice": 303
}, {
  "Item Name": "COINTTRAEU",
  "SellingPrice": 303
}, {
  "Item Name": "SAMBUCA",
  "SellingPrice": 258
}, {
  "Item Name": "KHALUA",
  "SellingPrice": 168
}, {
  "Item Name": "MARTINI BLANCO",
  "SellingPrice": 90
}, {
  "Item Name": "MARTINI ROSSO",
  "SellingPrice": 90
}, {
  "Item Name": "HENESSY VS 700",
  "SellingPrice": 7875
}, {
  "Item Name": "HENESSY VS 30",
  "SellingPrice": 348
}, {
  "Item Name": "MORPHEUS 750",
  "SellingPrice": 2182
}, {
  "Item Name": "MORPHEUS 180",
  "SellingPrice": 540
}, {
  "Item Name": "MORPHEUS 60",
  "SellingPrice": 191
}, {
  "Item Name": "MORPHEUS 30",
  "SellingPrice": 101
}, {
  "Item Name": "MANSION HOUSE 180",
  "SellingPrice": 292
}, {
  "Item Name": "MANSION HOUSE 90",
  "SellingPrice": 168
}, {
  "Item Name": "MANSION HOUSE 60",
  "SellingPrice": 90
}, {
  "Item Name": "MC BRANDY 60",
  "SellingPrice": 90
}, {
  "Item Name": "RED BULL ",
  "SellingPrice": 157
}, {
  "Item Name": "COKE",
  "SellingPrice": 45
}, {
  "Item Name": "SPRITE",
  "SellingPrice": 45
}, {
  "Item Name": "SODA",
  "SellingPrice": 33
}, {
  "Item Name": "DIET COKE",
  "SellingPrice": 56
}, {
  "Item Name": "TONIC WATER",
  "SellingPrice": 67
}, {
  "Item Name": "GINGER ALE",
  "SellingPrice": 67
}, {
  "Item Name": "LIME SODA",
  "SellingPrice": 45
}, {
  "Item Name": "LIME WATER",
  "SellingPrice": 45
}, {
  "Item Name": "PACKEGED WATER 1L",
  "SellingPrice": 39
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}]

myFun();
window.setInterval(showRows, 5000);
showRows();

function myFun() {
  addTable(tableValue);
}

function showRows() {
  $(".hidden:lt(10)").removeClass("hidden");
}

function addTable(tableValue) {
  var $tbl = $("
", {
      "class": "table"
    }),

    $tb = $("
"),
    $trh = $("
");

  var split = Math.round(tableValue.length / 4);
  for (i = 0; i < split; i++) {
    $tr = $("
", {
      class: "hidden"
    });
    for (j = 0; j < 4; j++) {
      $.each(tableValue[split * j + i], function(key, value) {

        $("", {
          "class": "text-left color" + (j + 1)
        }).html(value).appendTo($tr);
      });
    }
    $tr.appendTo($tb);
  }
  $tbl.append($tb);
  $("#DisplayTable").html($tbl);
}

tbody>tr>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
  white-space: nowrap;
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">

Edit
I have tried @Void's solution but that is not removing the hidden class,when I inspect the element then there is no class applied to tr it is showing as class=""

Body:
Instead of creating the rows after every 5 seconds, you can create the rows in one go and hide them all using a class .hidden. Then every 5 seconds make first 5 hidden rows visible.

$(".hidden:lt(5)").removeClass("hidden");

Call this every 5 seconds.

var tableValue = [{
    "Item Name": "MANCHOW  V SOUP",
    "SellingPrice": 100
  },
  {
    "Item Name": "MANCHOW NV SOUP ",
    "SellingPrice": 125
  },
  {
    "Item Name": "CEASER SALAD V",
    "SellingPrice": 175
  },
  {
    "Item Name": "CEASER SALAD NV",
    "SellingPrice": 230
  },
  {
    "Item Name": "GAMBUS REBOZADAS",
    "SellingPrice": 350
  },
  {
    "Item Name": "PANCO FISH FINGER",
    "SellingPrice": 270
  },
  {
    "Item Name": "MUSHROOM DUPLEX",
    "SellingPrice": 160
  },
  {
    "Item Name": "FRENCH FRIES",
    "SellingPrice": 99
  },
  {
    "Item Name": "HONEY GARLIC PRAWN",
    "SellingPrice": 350
  },
  {
    "Item Name": "CHICKEN MANCHURIAN",
    "SellingPrice": 180
  },
  {
    "Item Name": "MUSHROOM CHILLY",
    "SellingPrice": 120
  },
  {
    "Item Name": "SALT N PEPPER BABY CORN",
    "SellingPrice": 120
  },
  {
    "Item Name": "SOUTHERN STYLE CHICKEN",
    "SellingPrice": 210
  },
  {
    "Item Name": "PANEER NAGGETS",
    "SellingPrice": 210
  },
  {
    "Item Name": "HARA BHARA KEBAB",
    "SellingPrice": 160
  },
  {
    "Item Name": "CHICKEN TIKKA",
    "SellingPrice": 210
  },
  {
    "Item Name": "KALMI KEBAB",
    "SellingPrice": 250
  },
  {
    "Item Name": "PIZZA MARGARITTA",
    "SellingPrice": 200
  },
  {
    "Item Name": "PIZZA VEG FARMHOUSE",
    "SellingPrice": 200
  },
  {
    "Item Name": "BBQ CHICKEN PIZZA",
    "SellingPrice": 225
  },
  {
    "Item Name": "CHICKEN TIKKA PIZZA",
    "SellingPrice": 225
  },
  {
    "Item Name": "PESTO SAUCE",
    "SellingPrice": 175
  },
  {
    "Item Name": "ARABIATA",
    "SellingPrice": 160
  },
  {
    "Item Name": "PINK SAUCE",
    "SellingPrice": 160
  },
  {
    "Item Name": "GARBANZO BEAN SALAD",
    "SellingPrice": 90
  },
  {
    "Item Name": "MASALA PAPAD",
    "SellingPrice": 50
  },
  {
    "Item Name": "PEANUT MASALA",
    "SellingPrice": 60
  },
  {
    "Item Name": "GAJAR KA HALWA",
    "SellingPrice": 90
  },
  {
    "Item Name": "WATERMELON MARTINI",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Kiwi martini",
    "SellingPrice": 281.25
  },
  {
    "Item Name": " Apple gin",
    "SellingPrice": 225
  },
  {
    "Item Name": "Cucumber  cooler ",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Martini",
    "SellingPrice": 225
  },
  {
    "Item Name": "Pink lady",
    "SellingPrice": 225
  },
  {
    "Item Name": " Bloody marry",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Cosmopolitan",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Sex on the beach",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Bull frog",
    "SellingPrice": 506.25
  },
  {
    "Item Name": "Long  island iced tea ",
    "SellingPrice": 393.75
  },
  {
    "Item Name": "Pinacolada",
    "SellingPrice": 225
  },
  {
    "Item Name": "Daiquiri",
    "SellingPrice": 225
  },
  {
    "Item Name": "Mojito ",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Whisky sour",
    "SellingPrice": 281.25
  },
  {
    "Item Name": "Hot toddy",
    "SellingPrice": 225
  },
  {
    "Item Name": "Margarita",
    "SellingPrice": 337.5
  },
  {
    "Item Name": "Tequila sunrise",
    "SellingPrice": 337.5
  },
  {
    "Item Name": "Red sangria",
    "SellingPrice": 225
  },
  {
    "Item Name": "White sangria",
    "SellingPrice": 247.5
  },
  {
    "Item Name": "Rose sangria",
    "SellingPrice": 247.5
  },
  {
    "Item Name": "By chance special ",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Made in heaven",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Strawberry delight",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "DRAGON",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Mangochil ",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Cucumber cola",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Virgin mojito",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Virgin mary",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "Virgin pinacolada",
    "SellingPrice": 168.75
  },
  {
    "Item Name": "CORONA",
    "SellingPrice": 438.75
  },
  {
    "Item Name": "CRAFT BEERS",
    "SellingPrice": 337.5
  },
  {
    "Item Name": "BIRA WHITE 330",
    "SellingPrice": 157.5
  },
  {
    "Item Name": "BIRA BLONDE 330",
    "SellingPrice": 135
  },
  {
    "Item Name": "BIRA STRONG 650",
    "SellingPrice": 213.75
  },
  {
    "Item Name": "KINGFISHER PREMIUM 330",
    "SellingPrice": 123.75
  },
  {
    "Item Name": "KINGFISHER PREMIUM 650",
    "SellingPrice": 202.5
  },
  {
    "Item Name": "KINGFISHER PREMIUM 330",
    "SellingPrice": 123.75
  },
  {
    "Item Name": "KINGFISHER PREMIUM 650",
    "SellingPrice": 202.5
  },
  {
    "Item Name": "TESTING ITEM",
    "SellingPrice": 22
  }
]

myFun();
window.setInterval(showRows, 5000);
showRows();
function myFun() {
  addTable(tableValue);
}

function showRows(){
  $(".hidden:lt(5)").removeClass("hidden");
}

function addTable(tableValue) {
  var $tbl = $("<table />", {
      "class": "table"
    }),

    $tb = $("<tbody/>"),
    $trh = $("<tr/>");

  var split = Math.round(tableValue.length / 4);
  for (i = 0; i < split; i++) {
    $tr = $("<tr/>", {class: "hidden"});
    for (j = 0; j < 4; j++) {
      $.each(tableValue[split * j + i], function(key, value) {

        $("<td/>", {
          "class": "text-left color" + (j + 1)
        }).html(value).appendTo($tr);
      });
    }
    $tr.appendTo($tb);
  }
  $tbl.append($tb);
  $("#DisplayTable").html($tbl);
}

tbody>tr>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
  white-space: nowrap;
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}

.hidden {
  display: none;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<div id="DisplayTable">
</div>


问:
Converting array iteration to lambda function using Java8
I am trying to convert to Lambda function

So far I am able to convert the above code to lambda function like as shown below

```<code>Stream.of(acceptedDetails, rejectedDetails)
.filter(list -> !isNull(list) && list.length > 0)
.forEach(new Consumer<Object>() {
    public void accept(Object acceptedOrRejected) {
        String id;
        if(acceptedOrRejected instanceof EmployeeValidationAccepted) {
            id = ((EmployeeValidationAccepted) acceptedOrRejected).getId();
        } else {
            id = ((EmployeeValidationRejected) acceptedOrRejected).getAd().getId();
        }

        if(acceptedOrRejected instanceof EmployeeValidationAccepted) {
            dates1.add(new Integer(id.split("something")[1]));
            Integer empId = Integer.valueOf(id.split("something")[2]);
            empIds1.add(empId);
        } else {
            dates2.add(new Integer(id.split("something")[1]));
            Integer empId = Integer.valueOf(id.split("something")[2]);
            empIds2.add(empId);
        }
    }
});
</code>```

But still my goal was to avoid repeating the same logic and also to convert to Lambda function, still in my converted lambda function I feel its not clean and efficient.

This is just for my learning aspect I am doing this stuff by taking one existing code snippet.

Can anyone please tell me how can I improvise the converted Lambda function

答:
Generally, when you try to refactor code, you should only focus on the necessary changes.

Just because you’re going to use the Stream API, there is no reason to clutter the code with checks for null or empty arrays which weren’t in the loop based code. Neither should you change BigInteger to Integer.

Then, you have two different inputs and want to get distinct results from each of them, in other words, you have two entirely different operations. While it is reasonable to consider sharing common code between them, once you identified identical code, there is no sense in trying to express two entirely different operations as a single operation.

First, let’s see how we would do this for a traditional loop:

```<code>static void addToLists(String id, List<Integer> empIdList, List<BigInteger> dateList) {
    String[] array = id.split("-");
    dateList.add(new BigInteger(array[1]));
    empIdList.add(Integer.valueOf(array[2]));
}
</code>```

```<code>List<Integer> empIdAccepted = new ArrayList<>();
List<BigInteger> dateAccepted = new ArrayList<>();

for(EmployeeValidationAccepted acceptedDetail : acceptedDetails) {
    addToLists(acceptedDetail.getId(), empIdAccepted, dateAccepted);
}

List<Integer> empIdRejected = new ArrayList<>();
List<BigInteger> dateRejected = new ArrayList<>();

for(EmployeeValidationRejected rejectedDetail : rejectedDetails) {
    addToLists(rejectedDetail.getAd().getId(), empIdRejected, dateRejected);
}
</code>```

If we want to express the same as Stream operations, there’s the obstacle of having two results per operation. It truly took until JDK 12 to get a built-in solution:

```<code>static Collector<String,?,Map.Entry<List<Integer>,List<BigInteger>>> idAndDate() {
    return Collectors.mapping(s -> s.split("-"),
        Collectors.teeing(
            Collectors.mapping(a -> Integer.valueOf(a[2]), Collectors.toList()),
            Collectors.mapping(a -> new BigInteger(a[1]),  Collectors.toList()),
            Map::entry));
}
</code>```

```<code>Map.Entry<List<Integer>, List<BigInteger>> e;
e = Arrays.stream(acceptedDetails)
        .map(EmployeeValidationAccepted::getId)
        .collect(idAndDate());

List<Integer> empIdAccepted = e.getKey();
List<BigInteger> dateAccepted = e.getValue();

e = Arrays.stream(rejectedDetails)
    .map(r -> r.getAd().getId())
    .collect(idAndDate());

List<Integer> empIdRejected = e.getKey();
List<BigInteger> dateRejected = e.getValue();
</code>```

Since a method can’t return two values, this uses a Map.Entry to hold them.

To use this solution with Java versions before JDK 12, you can use the implementation posted at the end of this answer. You’d also have to replace Map::entry with AbstractMap.SimpleImmutableEntry::new then.

Or you use a custom collector written for this specific operation:

```<code>static Collector<String,?,Map.Entry<List<Integer>,List<BigInteger>>> idAndDate() {
    return Collector.of(
        () -> new AbstractMap.SimpleImmutableEntry<>(new ArrayList<>(), new ArrayList<>()),
        (e,id) -> {
            String[] array = id.split("-");
            e.getValue().add(new BigInteger(array[1]));
            e.getKey().add(Integer.valueOf(array[2]));
        },
        (e1, e2) -> {
            e1.getKey().addAll(e2.getKey());
            e1.getValue().addAll(e2.getValue());
            return e1;
        });
}
</code>```

In other words, using the Stream API does not always make the code simpler.

As a final note, we don’t need to use the Stream API to utilize lambda expressions. We can also use them to move the loop into the common code.

```<code>static <T> void addToLists(T[] elements, Function<T,String> tToId,
                           List<Integer> empIdList, List<BigInteger> dateList) {
    for(T t: elements) {
        String[] array = tToId.apply(t).split("-");
        dateList.add(new BigInteger(array[1]));
        empIdList.add(Integer.valueOf(array[2]));
    }
}
</code>```

```<code>List<Integer> empIdAccepted = new ArrayList<>();
List<BigInteger> dateAccepted = new ArrayList<>();
addToLists(acceptedDetails, EmployeeValidationAccepted::getId, empIdAccepted, dateAccepted);

List<Integer> empIdRejected = new ArrayList<>();
List<BigInteger> dateRejected = new ArrayList<>();
addToLists(rejectedDetails, r -> r.getAd().getId(), empIdRejected, dateRejected);
</code>```

Body:
I am trying to convert to Lambda function

So far I am able to convert the above code to lambda function like as shown below

Stream.of(acceptedDetails, rejectedDetails)
.filter(list -> !isNull(list) && list.length > 0)
.forEach(new Consumer<Object>() {
    public void accept(Object acceptedOrRejected) {
        String id;
        if(acceptedOrRejected instanceof EmployeeValidationAccepted) {
            id = ((EmployeeValidationAccepted) acceptedOrRejected).getId();
        } else {
            id = ((EmployeeValidationRejected) acceptedOrRejected).getAd().getId();
        }

        if(acceptedOrRejected instanceof EmployeeValidationAccepted) {
            dates1.add(new Integer(id.split("something")[1]));
            Integer empId = Integer.valueOf(id.split("something")[2]);
            empIds1.add(empId);
        } else {
            dates2.add(new Integer(id.split("something")[1]));
            Integer empId = Integer.valueOf(id.split("something")[2]);
            empIds2.add(empId);
        }
    }
});

But still my goal was to avoid repeating the same logic and also to convert to Lambda function, still in my converted lambda function I feel its not clean and efficient.

This is just for my learning aspect I am doing this stuff by taking one existing code snippet.

Can anyone please tell me how can I improvise the converted Lambda function

Body:
Generally, when you try to refactor code, you should only focus on the necessary changes.

Just because you’re going to use the Stream API, there is no reason to clutter the code with checks for null or empty arrays which weren’t in the loop based code. Neither should you change BigInteger to Integer.

Then, you have two different inputs and want to get distinct results from each of them, in other words, you have two entirely different operations. While it is reasonable to consider sharing common code between them, once you identified identical code, there is no sense in trying to express two entirely different operations as a single operation.

First, let’s see how we would do this for a traditional loop:

static void addToLists(String id, List<Integer> empIdList, List<BigInteger> dateList) {
    String[] array = id.split("-");
    dateList.add(new BigInteger(array[1]));
    empIdList.add(Integer.valueOf(array[2]));
}

List<Integer> empIdAccepted = new ArrayList<>();
List<BigInteger> dateAccepted = new ArrayList<>();

for(EmployeeValidationAccepted acceptedDetail : acceptedDetails) {
    addToLists(acceptedDetail.getId(), empIdAccepted, dateAccepted);
}

List<Integer> empIdRejected = new ArrayList<>();
List<BigInteger> dateRejected = new ArrayList<>();

for(EmployeeValidationRejected rejectedDetail : rejectedDetails) {
    addToLists(rejectedDetail.getAd().getId(), empIdRejected, dateRejected);
}

If we want to express the same as Stream operations, there’s the obstacle of having two results per operation. It truly took until JDK 12 to get a built-in solution:

static Collector<String,?,Map.Entry<List<Integer>,List<BigInteger>>> idAndDate() {
    return Collectors.mapping(s -> s.split("-"),
        Collectors.teeing(
            Collectors.mapping(a -> Integer.valueOf(a[2]), Collectors.toList()),
            Collectors.mapping(a -> new BigInteger(a[1]),  Collectors.toList()),
            Map::entry));
}

Map.Entry<List<Integer>, List<BigInteger>> e;
e = Arrays.stream(acceptedDetails)
        .map(EmployeeValidationAccepted::getId)
        .collect(idAndDate());

List<Integer> empIdAccepted = e.getKey();
List<BigInteger> dateAccepted = e.getValue();

e = Arrays.stream(rejectedDetails)
    .map(r -> r.getAd().getId())
    .collect(idAndDate());

List<Integer> empIdRejected = e.getKey();
List<BigInteger> dateRejected = e.getValue();

Since a method can’t return two values, this uses a Map.Entry to hold them.

To use this solution with Java versions before JDK 12, you can use the implementation posted at the end of this answer. You’d also have to replace Map::entry with AbstractMap.SimpleImmutableEntry::new then.

Or you use a custom collector written for this specific operation:

static Collector<String,?,Map.Entry<List<Integer>,List<BigInteger>>> idAndDate() {
    return Collector.of(
        () -> new AbstractMap.SimpleImmutableEntry<>(new ArrayList<>(), new ArrayList<>()),
        (e,id) -> {
            String[] array = id.split("-");
            e.getValue().add(new BigInteger(array[1]));
            e.getKey().add(Integer.valueOf(array[2]));
        },
        (e1, e2) -> {
            e1.getKey().addAll(e2.getKey());
            e1.getValue().addAll(e2.getValue());
            return e1;
        });
}

In other words, using the Stream API does not always make the code simpler.

As a final note, we don’t need to use the Stream API to utilize lambda expressions. We can also use them to move the loop into the common code.

static <T> void addToLists(T[] elements, Function<T,String> tToId,
                           List<Integer> empIdList, List<BigInteger> dateList) {
    for(T t: elements) {
        String[] array = tToId.apply(t).split("-");
        dateList.add(new BigInteger(array[1]));
        empIdList.add(Integer.valueOf(array[2]));
    }
}

List<Integer> empIdAccepted = new ArrayList<>();
List<BigInteger> dateAccepted = new ArrayList<>();
addToLists(acceptedDetails, EmployeeValidationAccepted::getId, empIdAccepted, dateAccepted);

List<Integer> empIdRejected = new ArrayList<>();
List<BigInteger> dateRejected = new ArrayList<>();
addToLists(rejectedDetails, r -> r.getAd().getId(), empIdRejected, dateRejected);