Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const latinDataReplace = (firstName, lastName) => {
- const maxGeneralLength = 25;
- const step1 = ({firstName, lastName}) => {
- if (firstName.length + lastName.length > maxGeneralLength) {
- firstName = firstName[0]
- }
- return {firstName, lastName};
- };
- const step2 = ({firstName, lastName}) => {
- if (lastName.indexOf('-') && (firstName.length + lastName.length) > maxGeneralLength) {
- lastName = lastName.slice(0, lastName.indexOf('-'));
- }
- return {firstName, lastName};
- };
- const step3 = ({firstName, lastName}) => {
- console.log({firstName, lastName}, 'step3');
- if (firstName.length + lastName.length > maxGeneralLength) {
- lastName = lastName.slice(0, maxGeneralLength - 1);
- }
- return {firstName, lastName};
- };
- const {latinFirstName, latinLastName} = Promise.resolve({firstName, lastName})
- .then(step1)
- .then(step2)
- .then(step3);
- return {latinFirstName, latinLastName};
- };
- const {latinFirstName, latinLastName} = latinDataReplace('', 'CHARNYSHEVICH-ALIAKSANDROVA');
- console.log({latinFirstName, latinLastName}, 'result');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement