{"size": 999, "ext": "js", "max_stars_repo_path": "2_HW_JS_Coding_Girls/05.n_fibonacci_numbers_2nd_way.js", "max_stars_repo_name": "Coding-Girls/JavaScript-Cource", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2_HW_JS_Coding_Girls/05.n_fibonacci_numbers_2nd_way.js", "max_issues_repo_name": "Coding-Girls/JavaScript-Cource", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2_HW_JS_Coding_Girls/05.n_fibonacci_numbers_2nd_way.js", "max_forks_repo_name": "Coding-Girls/JavaScript-Cource", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.5428571429, "max_line_length": 83, "alphanum_fraction": 0.5395395395}
/* Task 5*. Write a function that takes an integer number as a parameter and 
prints an appropriate number of Fibonacci numbers. */

function nFibonacciNumbers2ndWay(args) {
    let n = +args,
        current,
        previous = 1,
        beforePrevious = 0,
        i,
        arrFibonacci = [];

    for (i = 1; i <= n; i += 1) {
        if (i == 1) {
            current = beforePrevious;
        } else if (i == 2) {
            current = previous;
        } else {
            current = beforePrevious + previous;
            beforePrevious = previous;
            previous = current;
        }

        arrFibonacci.push(current);
    }

    console.log(arrFibonacci.join(', '));
}

// Input:                         Output:
nFibonacciNumbers2ndWay(1);   //  0
nFibonacciNumbers2ndWay(2);   //  0, 1
nFibonacciNumbers2ndWay(3);   //  0, 1, 1
nFibonacciNumbers2ndWay(10);  //  0, 1, 1, 2, 3, 5, 8, 13, 21, 34
nFibonacciNumbers2ndWay(14);  //  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233
