Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const latinDataReplace = (firstName, lastName) => {
  2.     const maxGeneralLength = 25;
  3.  
  4.     const step1 = ({firstName, lastName}) => {
  5.         if (firstName.length + lastName.length > maxGeneralLength) {
  6.             firstName = firstName[0]
  7.         }
  8.         return {firstName, lastName};
  9.     };
  10.  
  11.     const step2 = ({firstName, lastName}) => {
  12.         if (lastName.indexOf('-') && (firstName.length + lastName.length) > maxGeneralLength) {
  13.             lastName = lastName.slice(0, lastName.indexOf('-'));
  14.         }
  15.         return {firstName, lastName};
  16.     };
  17.  
  18.     const step3 = ({firstName, lastName}) => {
  19.         console.log({firstName, lastName}, 'step3');
  20.         if (firstName.length + lastName.length > maxGeneralLength) {
  21.             lastName = lastName.slice(0, maxGeneralLength - 1);
  22.         }
  23.         return {firstName, lastName};
  24.     };
  25.  
  26.     const {latinFirstName, latinLastName} = Promise.resolve({firstName, lastName})
  27.         .then(step1)
  28.         .then(step2)
  29.         .then(step3);
  30.     return {latinFirstName, latinLastName};
  31. };
  32.  
  33. const {latinFirstName, latinLastName} = latinDataReplace('', 'CHARNYSHEVICH-ALIAKSANDROVA');
  34. console.log({latinFirstName, latinLastName}, 'result');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement