From 171d0c3da38f325f6f2db3963363ed7e8ced985e Mon Sep 17 00:00:00 2001 From: fcanon <fcanon@nowhere.na> Date: Thu, 8 Jun 2017 09:03:39 -0400 Subject: [PATCH] fix Global Realism preset error by using _.uniq instead of a for loop --- src/pregmod/basenationalitiesControls.tw | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/pregmod/basenationalitiesControls.tw b/src/pregmod/basenationalitiesControls.tw index bedd7043f45..a8ad1c58c92 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 */ -- GitLab