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

JS-Advanced-Exercies- Arrays and Nested Arrays - Lab #552

Open
TsvetDimitrov opened this issue Apr 15, 2021 · 0 comments
Open

JS-Advanced-Exercies- Arrays and Nested Arrays - Lab #552

TsvetDimitrov opened this issue Apr 15, 2021 · 0 comments

Comments

@TsvetDimitrov
Copy link

TsvetDimitrov commented Apr 15, 2021

The task: here
The solution i am submitting works localy for me in VSC. I've tried to console.log, to see the input only, but still this error occurs:
Untitled

Anyway the code for the solution is:

function lastKNumbersSequence(nTimes, kLastEl){
    let result = [1];
    for(let i = 1; i < nTimes; i++){
        let startIndex = Math.max(0, i-kLastEl);
        let curElement = result.slice(startIndex, startIndex + kLastEl).reduce((acc, el) => acc + el, 0);
        result.push(curElement);
    }
    console.log(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant