{"size": 588, "ext": "js", "max_stars_repo_path": "src/utils/getColumnsCount.js", "max_stars_repo_name": "newsiberian/react-columned", "max_stars_repo_stars_event_min_datetime": "2019-09-24T10:25:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-26T02:21:56.000Z", "max_issues_repo_path": "src/utils/getColumnsCount.js", "max_issues_repo_name": "newsiberian/react-columned", "max_issues_repo_issues_event_min_datetime": "2021-03-11T02:48:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T01:41:47.000Z", "max_forks_repo_path": "covid-19/node_modules/react-columned/src/utils/getColumnsCount.js", "max_forks_repo_name": "ivanadokic/covid-19-project", "max_forks_repo_forks_event_min_datetime": "2019-10-24T02:11:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-31T09:28:49.000Z"}
{"max_stars_count": 9, "max_issues_count": 16, "max_forks_count": 4, "avg_line_length": 23.52, "max_line_length": 66, "alphanum_fraction": 0.5765306122}
// @flow

export default function getColumnsCount(
    params: number | { [string]: number },
    width: number
): number {
    if (typeof params === "number") {
        return parseInt(params);
    }

    const sortedWidths = Object.keys(params).sort(function(a, b) {
        return parseInt(a) - parseInt(b);
    });

    for (let i = 0; i < sortedWidths.length; i++) {
        const current = sortedWidths[i];
        if (width <= parseInt(current)) {
            return params[current];
        }
    }

    // Return last.
    return params[sortedWidths[sortedWidths.length - 1]];
}
