diff --git a/src/pregmod/basenationalitiesControls.tw b/src/pregmod/basenationalitiesControls.tw index bedd7043f450f738b3758ece6dfbada72f046fb6..a8ad1c58c9240cd9becc595b2bfbd5cdda7f05fa 100644 --- a/src/pregmod/basenationalitiesControls.tw +++ b/src/pregmod/basenationalitiesControls.tw @@ -14,22 +14,17 @@ <</if>> <br> -/* Generates cloned array of $nationalities, removing duplicates */ -<<set $nationalitiescheck = clone($nationalities)>> -<<for _i = 0; _i < $nationalitiescheck.length; _i++>> - <<set _nation = $nationalitiescheck[_i]>> - <<if $nationalitiescheck.count(_nation) > 1>> - <<set $nationalitiescheck.deleteAt(_i), _i-->> - <</if>> -<</for>> -<<set $nationalitiescheck.sort()>> +/* Generates cloned array of $nationalities, removing duplicates and then sorting */ +<<set $nationalitiescheck = _.uniq($nationalities, false).sort()>> /* Prints distribution of $nationalities, using $nationalitiescheck to render array */ +<<set _totalPercentage = 0>> <<for _i = 0; _i < $nationalitiescheck.length; _i++>> - <<set _nation = $nationalitiescheck[_i]>> - <<print _nation>> @@.orange;<<print (($nationalities.count(_nation)/$nationalities.length)*100).toFixed(2)>>%@@ -<<if _i < $nationalitiescheck.length-1>> | <</if>> + <<set _nation = $nationalitiescheck[_i], _percentage = (($nationalities.count(_nation)/$nationalities.length)*100), _totalPercentage += _percentage>> + <<print _nation>> @@.orange;<<print _percentage.toFixed(2)>>%@@ + <<if _i < $nationalitiescheck.length-1>> | <</if>> <</for>> +<<if _totalPercentage != 100>><br>//Percentages add up to _totalPercentage//<</if>> <br><br> /* Fine control tweaking of populations */