## Transform vcards into contacts using JavaScript functional programming

Context:

I am creating a React application using Ramda as an auxiliary library for functional programming.

Users can import contacts in the application. These contacts can be vCards.

I have written a function that:

1. Eliminate duplicates,
2. Eliminate companies,
3. Transforms the vcards data into contacts that the React application understands.

The contacts of the applications look like this:

``````{
Name: & # 39; Bob & # 39 ;,
Surname: & # 39; Mueller & # 39 ;,
Company: & # 39; X-Enterprises & # 39 ;,
Position: & # 39; CEO & # 39 ;,
contactDetails: & # 39; Cell phone: 555-55-5555 Email: bob.mueller@XE.com & # 39 ;,
Conversation topics: & # 39; We talk about politics & # 39;
City: & # 39; New York & # 39;
}
``````

So an empty contact looks like this:

``````const emptyContact = {
first name: & # 39; & # 39 ;,
Last name: & # 39; & # 39 ;,
company: & # 39; & # 39 ;,
position: & # 39; & # 39 ;,
Contact details: & # 39; & # 39 ;,
Conversation topics: & # 39; & # 39;
city: & # 39; & # 39;
}
``````

I will give you the accessories with which I try my function at the end, because they are very long. But here is the proof that I wrote to prove my function:

``````describe (& # 39; createVCardContacts () & # 39 ;, async assert => {
say({
given: & # 39; an array of vcard contacts & # 39 ;,
must: & # 39; return a set of valid contacts & # 39 ;,
Current: createVCardContacts (vCardData),
expected: parsedVCardData,
});
});
``````

Valid contacts here means there are no duplicates or companies.

Function:

So, here is the `createVCardContacts` function:

``````import * as R from & # 39; ramda & # 39 ;;
import * as RA from & # 39; ramda-adjunct & # 39 ;;
import * as R_ from & # 39; ramda-extension & # 39 ;;

// VCard data always has its value in index 3 and can be
// a matrix or a value
const getDataFromVCard = R.pipe (
R.ifElse (
R.
R_.isArray
)
)
R.nth (3)
);
export const nGetter = R.pipe (
getDataFromVCard,
R.takeWhile (R.complement (R.isEmpty))
);
export const orgGetter = R.pipe (
getDataFromVCard,
R.replace (& # 39 ;; & # 39 ;, & # 39; & # 39;)
);
export const bdayGetter = R.pipe (
getDataFromVCard,
R.concat (& # 39; Birthday: & # 39;)
);
export const titleGetter = getDataFromVCard;
export const noteGetter = getDataFromVCard;
export const adrGetter = R.pipe (
getDataFromVCard,
R.nth (3)
);
export const telGetter = R.pipe (
getDataFromVCard,
R.concat (& # 39; Cellular: & # 39;)
);
export const emailGetter = R.pipe (
getDataFromVCard,
R.concat (& # 39; Email: & # 39;)
);
const vCardEvolveObject = {
n: better
org: orgGetter,
bday: bdayGetter,
title: best letter,
note: note
tel: tel
email: emailGetter,
};
export const createVCardContacts = R.pipe (
// Remove duplicates by name
R.uniqBy (R.prop (& # 39; n & # 39;)),
// Remove companies
To refuse
R.both (
R.both (R. has (& # 39; fn & # 39;), R. has (& # 39; org & # 39;)),
R.converge (R.equals, [
R.pipe(
R.prop('fn'),
R.nth(3)
),
R.pipe(
R.prop('org'),
R.nth(3),
R.replace(';', '')
),
])
)
)
R.map (
R.
// Only pick up relevant keys, if they are present
R.pick (R.keys (vCardEvolveObject)),
// Transform object so that it only contains strings.
R.evolve (vCardEvolveObject),
R.assoc (& # 39; contactDetails & # 39 ;, & # 39; & # 39;),
// Build information for Bday contact details, phone and email
R.mapObjIndexed ((val, key, obj) =>
key === & # 39; contactDetails & # 39;
? R.trim (
/ indefinite / g,
& # 39; & # 39 ;,
`\$ {R.prop (& # 39; bday & # 39;) (obj)} \$ {R.prop (& # 39; tel & # 39;) (obj)} \$ {R.prop (& # 39; email & # 39;) (
obj
)} `
)
)
: val
)
// Get name and surname
R.converge (R.assoc (& # 39; lastName & # 39;), [
R.pipe(
R.prop('n'),
),
R.identity,
])
R.converge (R.assoc (& # 39; firstName & # 39;), [
R.pipe(
R.prop('n'),
R.drop(1),
R.reduce((acc, val) => R.trim(`\${acc} \${val}`), '')
),
R.identity,
])
// Delete irrelevant keys
R.dissoc (& # 39; n & # 39;),
R.dissoc (& # 39; bday & # 39;),
R.dissoc (& # 39; tel & # 39;),
R.dissoc (& # 39; email & # 39;),
// Rename relevant keys
RA.renameKeys ({
org: & # 39; company & # 39 ;,
adr: & # 39; city & # 39 ;,
title: & # 39; position & # 39 ;,
Note: & # 39; conversationTopics & # 39 ;,
})
)
)
R.merge (emptyContact)
);
``````

Here is why I post this question in the code review:

1. The function is very long, which means that it looks a bit like the spaghetti code.
2. I'm new to functional programming and maybe I'm doing bad things here.

If you could take a look and improve it, make it easier to read and / or interpret, and teach me to be very grateful! Thank you.

Accessories:

``````export const vCardData = [
{
version: ['version', {}, 'text', '3.0'],
prodid ['prodid', {}, 'text', '-//Apple Inc.//iOS 10.2//EN'],
north: ['n', {}, 'text', ['Mueller', 'Alex', '', '', '']],
fn ['fn', {}, 'text', 'Alex Mueller'],
tel: ['tel', { type: ['cell', 'voice', 'pref'] }, & # 39 ;, & # 39; + 555-5555-55 & # 39;],
Rev: ['rev', {}, 'text', '2018-03-01T08:05:33Z'],
}
{
version: ['version', {}, 'text', '3.0'],
prodid ['prodid', {}, 'text', '-//Apple Inc.//iOS 11.1.2//EN'],
north: ['n', {}, 'text', ['Mueller', 'Alex', '', '', '']],
fn ['fn', {}, 'text', 'Alex Mueller'],
tel: ['tel', { type: ['cell', 'voice', 'pref'] }, & # 39 ;, & # 39; + 555-5555-55 & # 39;],
Rev: ['rev', {}, 'text', '2018-02-14T16:01:30Z'],
}
{
version: ['version', {}, 'text', '3.0'],
prodid ['prodid', {}, 'text', '-//Apple Inc.//Mac OS X 10.14//EN'],
north: ['n', {}, 'text', ['', '', '', '', '']],
fn ['fn', {}, 'text', 'Apple GmbH'],
org: ['org', {}, 'text', 'Apple GmbH;'],
url [
'url',
{ group: 'item1', type: 'pref' },
'text',
'http://www.apple.com/de/',
],
xAbLabel:[&#39;xAbLabel&#39;{group:&#39;item1&#39;}&#39;text&#39;&#39;_\$!['xAbLabel'{group:'item1'}'text''_\$!['xAbLabel'{group:'item1'}'text''_\$!['xAbLabel'{group:'item1'}'text''_\$!\$

,
xAbShowAs: ['xAbShowAs', {}, 'text', 'COMPANY'],
Rev: ['rev', {}, 'text', '2019-02-28T21:07:48Z'],
}
{
version: ['version', {}, 'text', '3.0'],
prodid ['prodid', {}, 'text', '-//Apple Inc.//Mac OS X 10.14//EN'],
north: ['n', {}, 'text', ['Howenstedt', 'Jan', '', '', '']],
fn ['fn', {}, 'text', 'Jan Howenstedt'],
Rev: ['rev', {}, 'text', '2019-02-28T21:07:48Z'],
}
{
version: ['version', {}, 'text', '3.0'],
prodid ['prodid', {}, 'text', '-//Apple Inc.//iOS 12.1.4//EN'],
north: ['n', {}, 'text', ['Vesoc', 'Mark', '', '', '']],
fn ['fn', {}, 'text', 'Mark Vesoc'],
tel:

The
['tel', { type: ['cell', 'voice', 'pref'] }, & # 39 ;, & # 39; +49 173 5555555 & # 39;],
['tel', { type: ['work', 'voice'] }, & # 39 ;, & # 39; 0241 8943850 & # 39;],
],
bday ['bday', { value: 'date' }, 'date', '1991-06-26'],
xSocialprofile: [
'xSocialprofile',
{ type: 'whatsapp', xBundleidentifiers: 'net.whatsapp.WhatsApp' },
'text',
'x-a',
],
Rev: ['rev', {}, 'text', '2019-04-23T11:57:59Z'],
}
{
version: ['version', {}, 'text', '3.0'],
north: ['n', {}, 'text', ['Chapoupis', 'Nik', '', '', '']],
fn ['fn', {}, 'text', 'Nik Chapoupis'],
org: ['org', {}, 'text', 'Ordersome;'],
bday ['bday', { value: 'date' }, 'date', '1990-03-14'],
Title: ['title', {}, 'text', 'CEO'],
Note: ['note', {}, 'text', 'Looks for Designers'],
[
{ group: 'item1', type: ['home', 'pref'] }
& # 39; text & # 39 ;,
['', '', 'Engelbertstraße 33', 'Aachen', '', '52078', 'Germany'],
],
[
{ group: 'item2', type: 'work' },
'text',
['', '', 'Jülicherstraße\n72a', 'Aachen', '', '52070', 'Germany'],
],
],
['xAbadr', { group: 'item1' }, 'text', 'de'],
['xAbadr', { group: 'item2' }, 'text', 'de'],
],
tel: [
['tel', { type: ['cell', 'pref', 'voice'] }, & # 39 ;, text & # 39; +49 1578 5555555 & # 39;],
['tel', { type: ['work', 'voice'] }, & # 39 ;, & # 39; 0241 8943850 & # 39;],
],
url [
'url',
{ group: 'item3', type: 'pref' },
'text',
'http://ordersome.de',
],
xAblabel:

The[& # 39; xAblabel & # 39 ;, {group: & # 39; item3 & # 39;}, & # 39; text & # 39 ;, & # 39; _ \$!['xAblabel' {group: 'item3'} 'text' '_ \$!
['xAblabel'{group:'item3'}'text''_\$!\$

,[& # 39; xAblabel & # 39 ;, {group: & # 39; item4 & # 39;}, & # 39; text & # 39 ;, & # 39; _ \$!['xAblabel' {group: 'item4'} 'text' '_ \$!
['xAblabel'{group:'item4'}'text''_\$!\$

,
],
impp [
'impp',
& # 39; text & # 39 ;,
& # 39; xmpp: Hello% 20World & # 39 ;,
],
email: [
[
'email',
{ type: ['home', 'pref', 'internet'] }
& # 39; text & # 39 ;,
& # 39; nikolas@gmail.com & # 39 ;,
],
[
'email',
{ type: ['work', 'internet'] }
& # 39; text & # 39 ;,
& # 39; nikolaschapoupis@gmail.com & # 39 ;,
],
],
xAbdate: [
'xAbdate',
{ group: 'item4', type: 'pref' },
'text',
'2017-10-11',
],
xSocialprofile: [
'xSocialprofile',
'text',
],
& # 39; com / nikolasChap & # 39; [
'com/nikolasChap',
'text',
null,
],
prodid [
'prodid',
{},
'text',
'-//Apple Inc.//iCloud Web Address Book 1906B32//EN',
],
Rev: ['rev', {}, 'text', '2019-04-23T04:58:28Z'],
}
];

export const parsedVCardData = [
{
city: '',
company: '',
contactDetails: 'Cell phone: +555-5555-55',
conversationTopics: '',
firstName: 'Alex',
lastName: 'Mueller',
position: '',
},
{
city: '',
company: '',
contactDetails: '',
conversationTopics: '',
firstName: 'Jan',
lastName: 'Howenstedt',
position: '',
},
{
city: '',
company: '',
contactDetails: 'Birthday: 1991-06-26 Cell phone: +49 173 5555555',
conversationTopics: '',
firstName: 'Mark',
lastName: 'Vesoc',
position: '',
},
{
city: 'Aachen',
company: 'Ordersome',
contactDetails:
'Birthday: 1990-03-14 Cell phone: +49 1578 5555555 Email: nikolas@gmail.com',
conversationTopics: 'Looks for Designers',
firstName: 'Nik',
lastName: 'Chapoupis',
position: 'CEO',
},
];
``````

## Integer programming – Find the shortest route in a graph

If each edge of a graph $$G$$ is not weighted or has equal weights, then the shortest route between two nodes in that graph is the path that contains the least number of edges. This route can be obtained by BFS. Here, I consider that each weight of the edge is the minimum of the final vertices and the weight of the path is the sum of the edges divided by the number of edges in the path. I can not use BFS for such an algorithm. Please, suggest me a known algorithm to solve this problem. I would also prefer to know if I can use appropriate programming codes in C ++ to solve this problem.
enter the description of the image here

## Why do we use the microsoft forest programming language? [on hold]

As I read in an article, the programming language of Bosque is designed to write code that is simple, obvious and easy to reason for humans and machines. But if it's easy from all languages, why do not we use it in common?

## Programming languages: How to complete this edge detection method in Java?

Here I am given this method:

The activity is to add another for loop to the method that compares the current pixel with the lower pixel. You should set the current pixel to black if the colorDistance () is greater than the edgeDist; otherwise, set the current pixel blank. Basically, it is asking me to do the same as the loop already given, but vertically. I have put the question below:

I'm a bit confused about where to add the for loop in the method and how to do it exactly. Help would be appreciated! Thank you.

PD This is in Java language

## Copyright: If I simply look for a solution to a programming problem, should I quote the source?

For example, I needed to implement my own paging system, but I did not know the logic behind a system like that, so I looked for how to do it and then, after understanding how to do it, I would implement my own version without any Copy and paste, do I need to quote the fountain?

Or, another example, I did not know how to use a foreach for a dictionary, so I looked for it on my own to do it and then, after underestimating it, I implemented it without copying and pasting. Should I quote the source?

## Is this problem that is similar to linear integer programming also a NP-complete problem?

I have encountered this problem when trying to elaborate a table format algorithm.

It is very similar to standard linear programming (although it uses $$>$$ instead of $$<$$; I'm not very familiar with linear programming, but I think this does not matter much).

Leave $$vec v = (v_1, dots, v_n)$$ Be a vector of positive integer variables.

The problem is finding if there is an allowance for $$vec v$$ such that

$$v_1 + dots + v_n = c$$

Y

$$A vec v geq vec w$$

where $$c$$ it's a known constant, $$neighbor w$$ it is a known constant, and $$A$$ It is a matrix with the special property that each row of $$A$$ it's the way $$(0, dots, 0, 1, dots, 1, 0, dots, 0)$$.

That is, each inequality constraint only uses the coefficients 1 and 0, and only "consecutive" variables appear in each linear constraint.

I think this problem is NP-complete, but I have not been able to prove it.

I think that a reduction to exactly 1-in-3-SAT or set-cover is more likely to be successful (the variables would be literal / values ​​respectively and the rows in the matrix would correspond to the clauses / sets), but the restriction only restricts referring to consecutive variables does not seem strong enough to describe arbitrary clauses / sets.

Alternatively, I could be wrong, and this problem actually has an algorithm that I've been missing. (The problem that I'm really interested in solving is finding the smallest $$c$$ so the restrictions are still satisfactory, but I have expressed the problem in this way so that it remains a simple decision problem)

As an example, here is a small instance of this problem:

$$begin {array} {} v_1 + v_2 + v_3 + v_4 & = & 10 \ v_1 & geq & 1 \ v_2 & geq & 1 \ v_2 + v_3 & geq & 3 \ v_3 + v_4 & geq & 4 \ v_3 & geq & 1 \ v_4 & geq & 1 end {array}$$

which has a possible assignment $$vec v = (1, 1, 6, 2)$$.

## loop – Help with basic program in C of the introduction to programming class

The exercise asks for a program that reads a binary number in the form of a & # 39; char & # 39; of the keyboard and return to its corresponding in base 10. I have written a code but the values ​​it returns are wrong, can someone tell me the reason?

``````# include
int main () {} ()
int int (int a, int x) {}
int i, one;
un = 1;
(i = 0; i <x; i ++) {}
un = a * a;
};
return one;
}

char number[1024];
scanf ("% s", number);
int i;
int n = strlen (number) - 1;
int int = 0;
(i = 0, i <n + 1, i ++) {
new = new + (number[i] * expose (2, n-i));
}

printf ("% d", new);

}
``````

Also, I think some suggestions on how to make my code more readable do not fall foul hehehe

## Socket Programming /

I am trying to create a file transfer program using ARQ to stop and wait. Transfers files correctly mostly. But sometimes it transfers the file incorrectly. For example, the bold letters of the pdf files are converted into squares after the transfer.
example

## Buy WordPress programming and design services

#### Solve wordpress problem, WordPress error, WordPress problem

Are you looking for someone expert to transfer / migrate / move / copy your WordPress website to the new domain, new hosting or to the new directory?

You have come to the right place and will transfer your website to a new hosting or new domain name.

I can also move your website from the subdomain to the main domain, from and to the subfolder of the main domain.

My services:

Transfer the WordPress site from the old accommodation to the new accommodation

Transfer WP from one domain to another domain

Transfer WP from one domain to another subdomain

## Buy HTML and CSS programming services online

#### Install WordPress and WordPress Theme

My service offer:

• WordPress configured in your domain / hosting.
• Premium configuration and customization themes.
• Custom sidebar
• CSS edition.
• Create wonderful galleries
• Configure widgets.
• Help to edit your content.
• Migration of the WordPress site from the local server to the live server.

Because I:
– I'm a web professional
– Fast delivery
– Great communication.

– 100% satisfaction guarantee.

– Online support