Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Slicing #1499

Open
jithurjacob opened this issue Mar 28, 2016 · 1 comment
Open

Incorrect Slicing #1499

jithurjacob opened this issue Mar 28, 2016 · 1 comment

Comments

@jithurjacob
Copy link

Hi guys in slicing we are using (that.limit -rendered) in this if limit = 5 and rendered = 5 we won't be getting any output right ?

We need to use the minimum value of limit and rendered right ?

function async(suggestions) {
suggestions = suggestions || [];
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit < rendered ? that.limit : rendered));
that.async && that.trigger("asyncReceived", query);
}

This is my first time reporting an issue this solved my problem hope it's correct.

@MerickOWA
Copy link

I'm also running into this.

Making the code similar to the function sync(suggestions) { ... } would probably be cleaner..

            function async(suggestions) {
                if (!canceled && rendered < that.limit) {
                    that.cancel = $.noop;
                    suggestions = (suggestions || []).slice(0, that.limit - rendered);
                    rendered += suggestions.length;
                    that._append(query, suggestions);
                    that.async && that.trigger("asyncReceived", query);
                }
            }

Since we do the slice prior to "rendered" getting incremented, we should only slice off as many items as are available to fit within the limit. Since "rendered < that.limit" has already been tested by the if condition, then "that.limit - rendered" would always be positive and equal to the # of remaining items;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants