'use strict';

/**
 * Calculate amount of gift wrap
 * @param {String[]} dimensions - package dimensions like '2x2x2'
 * @return {Number} - sq. ft of gift wrap with slack
 */
export function amountOfGiftWrap(dimensions) {
  return dimensions.reduce((total, dimension) => {
    const [l, w, h] = dimension
      .split('x')
      .map(n => parseInt(n, 10));

    return total +
      2 * l * w +
      2 * l * h +
      2 * w * h +
      Math.min(l * w, l * h, w * h);
  }, 0);
}

/**
 * Calculate the amount of ribbon
 * @param {String[]} dimensions - package dimensions like '2x2x2'
 * @return {Number} - amount of ribbon needed
 */
export function amountOfRibbon(dimensions) {
  return dimensions.reduce((total, dimension) => {
    const [l, w, h] = dimension
      .split('x')
      .map(n => parseInt(n, 10));

    return total +
      2 * Math.min(l + w, l + h, w + h) +
      l * w * h;
  }, 0);
}

@@ -8,16 +8,267 @@
 rict';%0A%0A
+/**%0A * Parse dimension to numeric lengths%0A * @param %7BString%7D dimensions - dimensions in form of '2x2x2'%0A * @return %7BNumber%5B%5D%7D - lengths as numbers%0A */%0Afunction parseDimensions(dimensions) %7B%0A  return dimensions.split('x').map(n =%3E parseInt(n, 10));%0A%7D%0A%0A
 /**%0A * C
@@ -296,16 +296,16 @@
 ft wrap%0A
-
  * @para
@@ -535,33 +535,38 @@
 %5Bl, w, h%5D = 
-d
+parseD
 imension
 %0A      .spli
@@ -557,58 +557,19 @@
 sion
-%0A      .split('x')%0A      .map(n =%3E parseInt(n, 10)
+s(dimension
 );%0A%0A
@@ -962,25 +962,30 @@
 w, h%5D = 
-d
+parseD
 imension
 %0A      .
@@ -980,58 +980,19 @@
 sion
-%0A      .split('x')%0A      .map(n =%3E parseInt(n, 10)
+s(dimension
 );%0A%0A

create parseDimensions function