Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
---
id: a3f503de51cf954ede28891d
title: Find the Symmetric Difference
title: Trovare la differenza simmetrica
challengeType: 5
forumTopicId: 301611
dashedName: find-the-symmetric-difference
---

# --description--

The mathematical term <dfn>symmetric difference</dfn> (`△` or `⊕`) of two sets is the set of elements which are in either of the two sets but not in both. For example, for sets `A = {1, 2, 3}` and `B = {2, 3, 4}`, `A △ B = {1, 4}`.
Il termine matematico <dfn>differenza simmetrica</dfn> (`△` o `⊕`) di due insiemi è l'insieme di elementi che sono in uno dei due insiemi ma non in entrambi. Ad esempio, per gli insiemi `A = {1, 2, 3}` e `B = {2, 3, 4}`, `A △ B = {1, 4}`.

Symmetric difference is a binary operation, which means it operates on only two elements. So to evaluate an expression involving symmetric differences among *three* elements (`A △ B △ C`), you must complete one operation at a time. Thus, for sets `A` and `B` above, and `C = {2, 3}`, `A △ B △ C = (A △ B) △ C = {1, 4} △ {2, 3} = {1, 2, 3, 4}`.
La differenza simmetrica è un'operazione binaria, il che significa che opera solo su due elementi. Quindi per valutare un'espressione che comporta differenze simmetriche tra *tre* elementi (`A △ B △ C`), è necessario completare un'operazione alla volta. Così, per gli insiemi `A` e `B` di cui sopra, e `C = {2, 3}`, `A △ B △ C = (A △ B) △ C = {1, 4} △ {2, 3} = {1, 2, 3, 4}`.

# --instructions--

Create a function that takes two or more arrays and returns an array of their symmetric difference. The returned array must contain only unique values (*no duplicates*).
Crea una funzione che richiede due o più array e restituisce un array della loro differenza simmetrica. L'array restituito deve contenere solo valori univoci (*nessun duplicato*).

# --hints--

`sym([1, 2, 3], [5, 2, 1, 4])` should return `[3, 4, 5]`.
`sym([1, 2, 3], [5, 2, 1, 4])` dovrebbe restituire `[3, 4, 5]`.

```js
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5]);
```

`sym([1, 2, 3], [5, 2, 1, 4])` should contain only three elements.
`sym([1, 2, 3], [5, 2, 1, 4])` dovrebbe contenere solo tre elementi.

```js
assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3);
```

`sym([1, 2, 3, 3], [5, 2, 1, 4])` should return `[3, 4, 5]`.
`sym([1, 2, 3, 3], [5, 2, 1, 4])` dovrebbe restituire `[3, 4, 5]`.

```js
assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5]);
```

`sym([1, 2, 3, 3], [5, 2, 1, 4])` should contain only three elements.
`sym([1, 2, 3, 3], [5, 2, 1, 4])` dovrebbe contenere solo tre elementi.

```js
assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3);
```

`sym([1, 2, 3], [5, 2, 1, 4, 5])` should return `[3, 4, 5]`.
`sym([1, 2, 3], [5, 2, 1, 4, 5])` dovrebbe restituire `[3, 4, 5]`.

```js
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5]);
```

`sym([1, 2, 3], [5, 2, 1, 4, 5])` should contain only three elements.
`sym([1, 2, 3], [5, 2, 1, 4, 5])` dovrebbe contenere solo tre elementi.

```js
assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3);
```

`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` should return `[1, 4, 5]`
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` dovrebbe restituire `[1, 4, 5]`

```js
assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5]);
```

`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` should contain only three elements.
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` dovrebbe contenere solo tre elementi.

```js
assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3);
```

`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` should return `[1, 4, 5]`.
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` dovrebbe restituire `[1, 4, 5]`.

```js
assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5]);
```

`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` should contain only three elements.
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` dovrebbe contenere solo tre elementi.

```js
assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3);
```

`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` should return `[2, 3, 4, 6, 7]`.
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` dovrebbe restituire `[2, 3, 4, 6, 7]`.

```js
assert.sameMembers(
Expand All @@ -87,7 +87,7 @@ assert.sameMembers(
);
```

`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` should contain only five elements.
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` deve contenere solo cinque elementi.

```js
assert.equal(
Expand All @@ -96,7 +96,7 @@ assert.equal(
);
```

`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` should return `[1, 2, 4, 5, 6, 7, 8, 9]`.
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` dovrebbe restituire `[1, 2, 4, 5, 6, 7, 8, 9]`.

```js
assert.sameMembers(
Expand All @@ -112,7 +112,7 @@ assert.sameMembers(
);
```

`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` should contain only eight elements.
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` dovrebbe contenere solo otto elementi.

```js
assert.equal(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
---
id: 587d825c367417b2b2512c8f
title: Implement Merge Sort
title: Implementare Merge Sort
challengeType: 1
forumTopicId: 301614
dashedName: implement-merge-sort
---

# --description--

Another common intermediate sorting algorithm is merge sort. Like quick sort, merge sort also uses a divide-and-conquer, recursive methodology to sort an array. It takes advantage of the fact that it is relatively easy to sort two arrays as long as each is sorted in the first place. But we'll start with only one array as input, so how do we get to two sorted arrays from that? Well, we can recursively divide the original input in two until we reach the base case of an array with one item. A single-item array is naturally sorted, so then we can start combining. This combination will unwind the recursive calls that split the original array, eventually producing a final sorted array of all the elements. The steps of merge sort, then, are:
Un altro algoritmo di ordinamento intermedio comune è Merge Sort. Come Quick Sort, anche Merge Sort utilizza una metodologia ricorsiva divide-et-impera per ordinare un array. Esso si avvale del fatto che è relativamente semplice ordinare due array se ciascuno di essi è già ordinato. Ma inizieremo con un solo array come input, quindi come arriviamo a due array ordinati partendo da quello? Bene, possiamo dividere ricorsivamente a metà l'input originale fino a raggiungere il caso base di un array con un elemento. Un array con un singolo elemento è naturalmente ordinato, quindi possiamo iniziare a combinare. Questa combinazione darà il via alle chiamate ricorsive che dividono l'array originale, producendo alla fine un array finale ordinato di tutti gli elementi. I passi di Merge Sort, sono quindi:

**1)** Recursively split the input array in half until a sub-array with only one element is produced.
**1)** Dividi ricorsivamente l'array di input a metà finché non viene prodotto un sotto-array con un solo elemento.

**2)** Merge each sorted sub-array together to produce the final sorted array.
**2)** Unisci tutti i sottoarray ordinati per produrre l'array finale ordinato.

Merge sort is an efficient sorting method, with time complexity of *O(nlog(n))*. This algorithm is popular because it is performant and relatively easy to implement.
Il Merge Sort è un metodo di ordinamento efficiente, con complessità temporale di *O(nlog(n))*. Questo algoritmo è popolare perché è performante e relativamente facile da implementare.

As an aside, this will be the last sorting algorithm we cover here. However, later in the section on tree data structures we will describe heap sort, another efficient sorting method that requires a binary heap in its implementation.
A parte questo, questo sarà l'ultimo algoritmo di ordinamento che tratteremo qui. Tuttavia, più tardi nella sezione sulle strutture di dati ad albero descriveremo Heap Sort, un altro metodo di ordinamento efficiente che richiede un heap binario nella sua implementazione.

**Instructions:** Write a function `mergeSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. A good way to implement this is to write one function, for instance `merge`, which is responsible for merging two sorted arrays, and another function, for instance `mergeSort`, which is responsible for the recursion that produces single-item arrays to feed into merge. Good luck!
**Istruzioni:** Scrivi una funzione `mergeSort` che prende un array di interi come input e restituisce un array di questi interi in ordine dal più piccolo al più grande. Un buon modo per implementarlo è quello di scrivere una funzione, per esempio `merge`, che si occupa dell'unione di due array, e un'altra funzione, per esempio `mergeSort`, che è responsabile della ricorsione e che produce array di elementi singoli da fornire a Merge. Buona fortuna!

# --hints--

`mergeSort` should be a function.
`mergeSort` dovrebbe essere una funzione.

```js
assert(typeof mergeSort == 'function');
```

`mergeSort` should return a sorted array (least to greatest).
`mergeSort` dovrebbe restituire un array ordinato (dal più piccolo al più grande).

```js
assert(
Expand Down Expand Up @@ -56,7 +56,7 @@ assert(
);
```

`mergeSort` should return an array that is unchanged except for order.
`mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` dovrebbe restituire un array invariato tranne che per l'ordine.

```js
assert.sameMembers(
Expand All @@ -83,7 +83,7 @@ assert.sameMembers(
);
```

`mergeSort` should not use the built-in `.sort()` method.
`mergeSort` non dovrebbe utilizzare il metodo integrato `.sort()`.

```js
assert(isBuiltInSortUsed());
Expand Down Expand Up @@ -117,8 +117,6 @@ function mergeSort(array) {
return array;
// Only change code above this line
}

mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```

# --solutions--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
id: 587d8259367417b2b2512c85
title: Implement Selection Sort
title: Implementare Selection Sort
challengeType: 1
forumTopicId: 301616
dashedName: implement-selection-sort
---

# --description--

Here we will implement selection sort. Selection sort works by selecting the minimum value in a list and swapping it with the first value in the list. It then starts at the second position, selects the smallest value in the remaining list, and swaps it with the second element. It continues iterating through the list and swapping elements until it reaches the end of the list. Now the list is sorted. Selection sort has quadratic time complexity in all cases.
Qui implementeremo Selection Sort. Selection Sort funziona selezionando il valore minimo in una lista e scambiandolo con il primo valore dell'elenco. Poi inizia dalla seconda posizione, seleziona il valore più piccolo nella lista rimanente e lo scambia con il secondo elemento. Continua a iterare attraverso la lista e scambiare gli elementi fino a raggiungere la fine della lista. Ora la lista è ordinata. Il selection sort ha una complessità di tempo quadratica in tutti i casi.

**Instructions**: Write a function `selectionSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
**Istruzioni:** Scrivi una funzione `selectionSort` che prende un array di interi come input e restituisce un array di questi interi in ordine dal più piccolo al più grande.

# --hints--

`selectionSort` should be a function.
`selectionSort` dovrebbe essere una funzione.

```js
assert(typeof selectionSort == 'function');
```

`selectionSort` should return a sorted array (least to greatest).
`selectionSort` dovrebbe restituire un array ordinato (dal più piccolo al più grande).

```js
assert(
Expand Down Expand Up @@ -48,7 +48,7 @@ assert(
);
```

`selectionSort` should return an array that is unchanged except for order.
`selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` dovrebbe restituire un array invariato tranne che per l'ordine.

```js
assert.sameMembers(
Expand All @@ -75,7 +75,7 @@ assert.sameMembers(
);
```

`selectionSort` should not use the built-in `.sort()` method.
`selectionSort` non dovrebbe usare il metodo integrato `.sort()`.

```js
assert(isBuiltInSortUsed());
Expand Down Expand Up @@ -109,9 +109,6 @@ function selectionSort(array) {
return array;
// Only change code above this line
}


selectionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```

# --solutions--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
id: 587d8252367417b2b2512c67
title: Add Elements at a Specific Index in a Linked List
title: Aggiungere elementi ad un indice specifico in una lista collegata
challengeType: 1
forumTopicId: 301619
dashedName: add-elements-at-a-specific-index-in-a-linked-list
---

# --description--

Let's create a addAt(index,element) method that adds an element at a given index. Just like how we remove elements at a given index, we need to keep track of the currentIndex as we traverse the linked list. When the currentIndex matches the given index, we would need to reassign the previous node's next property to reference the new added node. And the new node should reference the next node in the currentIndex. Returning to the conga line example, a new person wants to join the line, but he wants to join in the middle. You are in the middle of the line, so you take your hands off of the person ahead of you. The new person walks over and puts his hands on the person you once had hands on, and you now have your hands on the new person.
Creiamo un metodo addAt(index,element) che aggiunge un elemento ad un dato indice. Proprio come come quando rimuoviamo gli elementi in un dato indice, dobbiamo tenere traccia del currentIndex mentre attraversiamo la lista collegata. Quando l'indice corrente corrisponde all'indice dato, dovremmo riassegnare la proprietà next del nodo precedente per fare riferimento al nuovo nodo aggiunto. E il nuovo nodo dovrebbe fare riferimento al nodo successivo in currentIndex. Tornando all'esempio della linea conga, una nuova persona vuole unirsi alla linea, ma vuole unirsi nel mezzo. Tu sei in mezzo alla linea, così togli le mani dalla persona che ti sta davanti. La nuova persona si inserisce e mette le mani sulla persona sulla quale prima avevi le tue mani, e tu ora metti le mani sulla nuova persona.

# --instructions--

Create an `addAt(index,element)` method that adds an element at a given index. Return false if an element could not be added. **Note:** Remember to check if the given index is a negative or is longer than the length of the linked list.
Crea un metodo `addAt(index,element)` che aggiunge un elemento ad un dato indice. Restituisce falso se un elemento non può essere aggiunto. **Nota:** Ricordati di controllare se l'indice fornito è negativo o è più lungo della lunghezza dell'elenco.

# --hints--

Your `addAt` method should reassign `head` to the new node when the given index is 0.
Il tuo metodo `addAt` dovrebbe riassegnare `head` al nuovo nodo quando l'indice dato è 0.

```js
assert(
Expand All @@ -30,7 +30,7 @@ assert(
);
```

Your `addAt` method should increase the length of the linked list by one for each new node added to the linked list.
Il tuo metodo `addAt` dovrebbe aumentare di uno la lunghezza della lista collegata per ogni nuovo nodo aggiunto alla lista.

```js
assert(
Expand All @@ -44,7 +44,7 @@ assert(
);
```

Your `addAt` method should return `false` if a node was unable to be added.
Il tuo metodo `addAt` dovrebbe restituire `false` se non è stato possibile aggiungere un nodo.

```js
assert(
Expand Down
Loading