how to improve this function that converts a flat array into a tree?
问题 I have this function that converts a flat array to a tree based on a path property. This is my data : const input = [ {"name":"brussels_district_north","path":"Brussels/Brussels CBD/North"}, {"name":"brussels_district_louise","path":"Brussels/Brussels CBD/Louise"}, {"name":"brussels_district_west","path":"Brussels/Brussels Decentralised/West"}, {"name":"brussels_district_léopold","path":"Brussels/Brussels CBD/Léopold"}, {"name":"brussels_district_airport","path":"Brussels/Brussels Periphery