{"ScriptPreparationCode":null,"TestCases":[{"Name":"push1","Code":"const input = [\r\n { type: \u0027a\u0027, distance: 5 },\r\n { type: \u0027c\u0027, distance: 3 },\r\n { type: \u0027b\u0027, distance: 6 },\r\n { type: \u0027c\u0027, distance: 12 },\r\n { type: \u0027b\u0027, distance: 1 },\r\n { type: \u0027a\u0027, distance: 5 },\r\n { type: \u0027b\u0027, distance: 6 },\r\n { type: \u0027a\u0027, distance: -1 },\r\n { type: \u0027c\u0027, distance: 9 },\r\n { type: \u0027d\u0027, distance: 10 }\r\n]\r\n\r\nconst normalize = (arr) =\u003E arr\r\n .filter(el =\u003E el.type !== \u0027a\u0027 \u0026\u0026 el.distance \u003E= 0)\r\n .reduce((acc, el) =\u003E {\r\n if (el.distance \u003C 4) acc.near.push(el);\r\n else if (el.distance \u003C 8) acc.medium.push(el);\r\n else if (el.distance \u003C= 10) acc.far.push(el);\r\n return acc;\r\n },\r\n {\r\n near:[],\r\n medium:[],\r\n far:[]\r\n })","IsDeferred":false},{"Name":"Spread","Code":"const input = [\r\n { type: \u0027a\u0027, distance: 5 },\r\n { type: \u0027c\u0027, distance: 3 },\r\n { type: \u0027b\u0027, distance: 6 },\r\n { type: \u0027c\u0027, distance: 12 },\r\n { type: \u0027b\u0027, distance: 1 },\r\n { type: \u0027a\u0027, distance: 5 },\r\n { type: \u0027b\u0027, distance: 6 },\r\n { type: \u0027a\u0027, distance: -1 },\r\n { type: \u0027c\u0027, distance: 9 },\r\n { type: \u0027d\u0027, distance: 10 }\r\n]\r\n\r\nfunction normalizeInput(input) {\r\n\r\n return input.reduce((accum, item) =\u003E {\r\n\r\n if (item.type !== \u0027a\u0027 \u0026\u0026 item.distance \u003E= 0)\r\n\r\n if (item.distance \u003C 4 ) accum.near = [...accum.near, item]\r\n else if (item.distance \u003C 8 ) accum.medium = [...accum.medium, item]\r\n else if (item.distance \u003C= 10 ) accum.far = [...accum.far, item]\r\n\r\n return accum;\r\n },{\r\n near:[],\r\n medium:[],\r\n far:[]\r\n })\r\n}","IsDeferred":false},{"Name":"push2","Code":"const input = [\r\n { type: \u0027a\u0027, distance: 5 },\r\n { type: \u0027c\u0027, distance: 3 },\r\n { type: \u0027b\u0027, distance: 6 },\r\n { type: \u0027c\u0027, distance: 12 },\r\n { type: \u0027b\u0027, distance: 1 },\r\n { type: \u0027a\u0027, distance: 5 },\r\n { type: \u0027b\u0027, distance: 6 },\r\n { type: \u0027a\u0027, distance: -1 },\r\n { type: \u0027c\u0027, distance: 9 },\r\n { type: \u0027d\u0027, distance: 10 }\r\n]\r\n\r\nconst norm = (input) =\u003E input.reduce((acc, item) =\u003E {\r\n\r\n if (item.type !== \u0027a\u0027 \u0026\u0026 item.distance \u003E= 0)\r\n\r\n if (item.distance \u003C 4) acc.near.push(item);\r\n else if (item.distance \u003C 8) acc.medium.push(item);\r\n else if (item.distance \u003C= 10) acc.far.push(item);\r\n\r\n return acc;\r\n},{\r\n near:[],\r\n medium:[],\r\n far:[]\r\n})","IsDeferred":false}]}