Skip to content

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

@TsvetDimitrov

Description

@TsvetDimitrov

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions