Build product variant labels
Turn structured option values into concise labels for a product variant picker.EasyE-commerce Product Modeling
20 min0% acceptance
Description
Implement buildVariantLabels for product variants whose values align with a shared optionNames array. Return a new display model for each variant with its id, availability, and a label made from Option: Value pairs joined by ' / '.
Requirements
The solution exports a callable function named buildVariantLabels.
Each value is paired with the option name at the same index.
Pairs use the exact format Option: Value and multiple pairs are joined by ' / '.
Each result preserves the variant's id and available value.
Result variants remain in the same order as the input variants.
An empty variants array returns an empty array.
The function does not mutate optionNames, variants, or nested values arrays.
Size and color
Input
buildVariantLabels(['Size', 'Color'], [{ id: 'v1', values: ['M', 'Black'], available: true }])Expected output
[{ id: 'v1', label: 'Size: M / Color: Black', available: true }]Constraints
optionNames contains between 1 and 3 non-empty stringsEvery variant values array has the same length as optionNamesVariant ids are unique within the inputThe input may contain up to 2000 variants
Hints
Hint 1
Pair option names and variant values by their shared index before formatting any text.
Hint 2
Build each Option: Value segment independently, then join the segments with the required separator.
Hint 3
Return a fresh display object for every variant and leave the caller's arrays untouched.
arraysmappingstrings