Sure! Below is the new code.
var fs = FeatureSetByPortalItem(
Portal("https://.maps.arcgis.com"),
// portal item id
"178eb292ce436450b85dc249bd3069741",
0,
['Contest_title'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
for (var f in fs) {
var contest = Decode(f["Contest_title"],"President of the United States (REP)","A",
"United States Senator (REP)", "C",
"Attorney General (REP)", "E",
"Auditor General (REP)", "G",
"State Treasurer (REP)", "I",
"Representative in Congress -13th District (REP)", "K",
"Representative in the General Assembly -78th District (REP)", "O"
"Delegate to the Republican National Convention (REP)" , "M",
"Alternate Delegate to the Republican National Convention (REP)", "P",
"Republican Committee Person - Bedford Borough West (REP)", "Q",
"Republican Committee Person - Bedford Township 1 (REP)", "R",
"Republican Committee Person - Bedford Township 2 (REP)", "S",
"Republican Committee Person - Everett Borough (REP)", "T",
"Republican Committee Person - Hopewell Township (REP)", "U",
"Republican Committee Person - King Township (REP)", "V",
"Republican Committee Person - West Providence Township (REP)", "W",
"Republican Committee Person - West St. Clair Township (REP)", "X",
"Republican Committee Person - Woodbury Township (REP)", "Y",
"President of the United States (DEM)", "B",
"United States Senator (DEM)", "D",
"Attorney General (DEM)", "F",
"Auditor General (DEM)", "H",
"State Treasurer (DEM)", return "J",
"Representative in Congress -13th District (DEM)", "L"
"Delegate to the Democratic National Convention (DEM)", "N",
"Unsatisfactory");
feat = {
attributes: {
Contest_ID: contest,
},
};
Push(features, feat);
}
var choicesDict = {
'fields': [
{ 'name': 'Contest_ID', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['Contest_ID'],
[{ name: 'Contest_ID', expression: 'Contest_ID', statistic: 'MAX' }]);