{"size": 407, "ext": "js", "max_stars_repo_path": "tutorials/cracking-the-code-interview/countSwaps.js", "max_stars_repo_name": "jonasraoni/hackerrank", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tutorials/cracking-the-code-interview/countSwaps.js", "max_issues_repo_name": "jonasraoni/hackerrank", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tutorials/cracking-the-code-interview/countSwaps.js", "max_forks_repo_name": "jonasraoni/hackerrank", "max_forks_repo_forks_event_min_datetime": "2022-01-22T16:45:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T16:45:30.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 23.9411764706, "max_line_length": 51, "alphanum_fraction": 0.4963144963}
//+ Jonas Raoni Soares Silva
//@ http://raoni.org

function countSwaps(a) {
	let swaps = 0;
	for (let l = a.length, j = 0, i = l; i--; ++j) {
		for (let k = l; --k > j;) {
			if (a[k] < a[k - 1]) {
				++swaps;
				[a[k], a[k - 1]] = [a[k - 1], a[k]];
			}
		}
	}
	console.log(`Array is sorted in ${swaps} swaps.`);
	console.log(`First Element: ${a[0]}`);
	console.log(`Last Element: ${a[a.length - 1]}`);
}