{"size": 974, "ext": "js", "max_stars_repo_path": "Section 3 and 4_Code/3And4/4/4/loadData.js", "max_stars_repo_name": "PacktPublishing/Mastering-D3.js-5-", "max_stars_repo_stars_event_min_datetime": "2019-06-10T11:53:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T08:21:08.000Z", "max_issues_repo_path": "Section 3 and 4_Code/3And4/4/4/loadData.js", "max_issues_repo_name": "PacktPublishing/Mastering-D3.js-5-", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Section 3 and 4_Code/3And4/4/4/loadData.js", "max_forks_repo_name": "PacktPublishing/Mastering-D3.js-5-", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.037037037, "max_line_length": 67, "alphanum_fraction": 0.613963039}
function getTop(int, data){
	//sort array
	let sortedData = data.sort(function(a, b){
		return (b["GNI"] - a["GNI"])
	})
	return sortedData.slice(1, (int + 1))
}

function groupByLevel(srcData){
	let resArr = []
	
	srcData.forEach(d => {
		
		//check if this level is in array
		let isInArr = resArr.filter(ind => ind.level == d.IncomeGroup)[0]
		
		//if not in array, add to array with value of 1
		if(isInArr == undefined){
			let thisObj = {
				level: d.IncomeGroup,
				count: 1
			}
			resArr.push(thisObj)
		}

		//if in array, add to array value
		if(isInArr !== undefined){
			return resArr.map(obj => {
				if(obj.level == d.IncomeGroup){
					obj.count = obj.count + 1;
				}
				return obj
			})

		}
		
	})
	
	return resArr
}

function prepData(fileName){

	return new Promise((res, rej) => {
		let resData = null;
		//load csv data, assign to var
		return d3.csv(fileName).then(data => {

			let groupedData = groupByLevel(data)

			res(groupedData)
		})
	})
}