{"ScriptPreparationCode":"var id = \u0022085805540784\u0022;\r\nvar variants = [\r\n {\r\n id: \u0022085805540753\u0022,\r\n shade: {\r\n normalizedColor: \u0022BLACK\u0022,\r\n editorialColor: \u0022Black\u0022,\r\n swatchColor: \u0022121212\u0022,\r\n swatchImage: \u0022\u0022,\r\n __typename: \u0022Shade\u0022\r\n },\r\n size: null,\r\n price: {\r\n numericalPrice: 32,\r\n formattedPrice: \u0022$32\u0022,\r\n __typename: \u0022Price\u0022\r\n },\r\n stockLevel: 3,\r\n maxOrderQuantity: 6,\r\n __typename: \u0022Variant\u0022\r\n },\r\n {\r\n id: \u0022085805540784\u0022,\r\n shade: {\r\n normalizedColor: \u0022BROWN\u0022,\r\n editorialColor: \u0022Brown\u0022,\r\n swatchColor: \u00228f3a1d\u0022,\r\n swatchImage: \u0022\u0022,\r\n __typename: \u0022Shade\u0022\r\n },\r\n size: null,\r\n price: {\r\n numericalPrice: 32,\r\n formattedPrice: \u0022$32\u0022,\r\n __typename: \u0022Price\u0022\r\n },\r\n stockLevel: 4,\r\n maxOrderQuantity: 6,\r\n __typename: \u0022Variant\u0022\r\n },\r\n {\r\n id: \u0022085805540821\u0022,\r\n shade: {\r\n normalizedColor: \u0022BLUE\u0022,\r\n editorialColor: \u0022Blue\u0022,\r\n swatchColor: \u00221c418d\u0022,\r\n swatchImage: \u0022\u0022,\r\n __typename: \u0022Shade\u0022\r\n },\r\n size: null,\r\n price: {\r\n numericalPrice: 32,\r\n formattedPrice: \u0022$32\u0022,\r\n __typename: \u0022Price\u0022\r\n },\r\n stockLevel: 2,\r\n maxOrderQuantity: 6,\r\n __typename: \u0022Variant\u0022\r\n },\r\n {\r\n id: \u0022085805540852\u0022,\r\n shade: {\r\n normalizedColor: \u0022PURPLE\u0022,\r\n editorialColor: \u0022Purple\u0022,\r\n swatchColor: \u0022903388\u0022,\r\n swatchImage: \u0022\u0022,\r\n __typename: \u0022Shade\u0022\r\n },\r\n size: null,\r\n price: {\r\n numericalPrice: 32,\r\n formattedPrice: \u0022$32\u0022,\r\n __typename: \u0022Price\u0022\r\n },\r\n stockLevel: 8,\r\n maxOrderQuantity: 6,\r\n __typename: \u0022Variant\u0022\r\n }\r\n];\r\n\r\nlet reduceArr = [],\r\n findFilterArr = [];","TestCases":[{"Name":"find \u0026 filter - 2 loops","Code":"const findFilter = (candidateAr, id) =\u003E {\r\n if (candidateAr[0].id === id) {\r\n return candidateAr;\r\n }\r\n const findVariant = candidateAr.find(variant =\u003E variant.id === id);\r\n if (findVariant) {\r\n const variantsWithout = candidateAr.filter(variant =\u003E variant.id !== id);\r\n const newVariants = [findVariant].concat(variantsWithout);\r\n return newVariants;\r\n }\r\n \r\n return candidateAr;\r\n\r\n};\r\n\r\nfindFilterArr = findFilter(variants, id);","IsDeferred":false},{"Name":"reduce - 1 loop","Code":"const sortArr = variants.reduce((acc, variant) =\u003E {\r\n if (variant.id === id) {\r\n \tacc.firstVariant = variant\r\n \treturn acc;\r\n }\r\n acc.remVariants.push(variant)\r\n return acc;\r\n}, { firstVariant:{}, remVariants:[]});\r\n \r\nconst { firstVariant, remVariants } = sortArr;\r\n \r\nreduceArr = [ firstVariant, ...remVariants];\r\n","IsDeferred":false}]}