Skip to content

Instantly share code, notes, and snippets.

@bubnenkoff
Created November 24, 2020 11:17
Show Gist options
  • Save bubnenkoff/1d9be241c1381f6b54bd0d2ffef9a6a7 to your computer and use it in GitHub Desktop.
Save bubnenkoff/1d9be241c1381f6b54bd0d2ffef9a6a7 to your computer and use it in GitHub Desktop.
const input = {
dishonest_total: [3,6,2,7,1,9],
customer_inn_and_name_list: ["aa", "bb", "cc", "dd", "ee", "ff"],
dishonest_rest: [5,1,6,1,4,1],
dishonest_true: [0,3,3,8,1,1]
}
const merged_array = []
for(var i = 0; i < input.customer_inn_and_name_list.length; i++) {
merged_array.push({
customer_inn_and_name_list: input.customer_inn_and_name_list[i],
dishonest_total: input.dishonest_total[i]
});
}
merged_array.sort((a, b) => a.dishonest_total - b.dishonest_total)
const output = merged_array.reduce((arr, val) => {
if (!arr.customer_inn_and_name_list) arr.customer_inn_and_name_list = []
if (!arr.dishonest_total) arr.dishonest_total = []
arr.customer_inn_and_name_list.push(val.customer_inn_and_name_list);
arr.dishonest_total.push(val.dishonest_total);
return arr;
}, {});
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment