chore(i18n,curriculum): update translations
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
e139fbcf13
commit
c1fb339bbc
@ -13,7 +13,7 @@ La programmazione funzionale riguarda la creazione e l'utilizzo di funzioni non
|
||||
L'ultima sfida ha introdotto il metodo `concat` come modo per combinare degli array in uno nuovo senza mutare gli array originali. Confronta `concat` con il metodo `push`. `push` aggiunge un elemento alla fine dello stesso array sul quale viene richiamato, mutando quello stesso array. Ecco un esempio:
|
||||
|
||||
```js
|
||||
var arr = [1, 2, 3];
|
||||
const arr = [1, 2, 3];
|
||||
arr.push([4, 5, 6]);
|
||||
```
|
||||
|
||||
@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
nonMutatingPush(first, second);
|
||||
```
|
||||
|
||||
@ -82,7 +83,6 @@ nonMutatingPush(first, second);
|
||||
function nonMutatingPush(original, newItem) {
|
||||
return original.concat(newItem);
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
nonMutatingPush(first, second);
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
```
|
||||
|
@ -77,7 +77,6 @@ function urlSlug(title) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
function urlSlug(title) {
|
||||
return title.trim().split(/\s+/).join("-").toLowerCase();
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ La tua funzione `incrementer` dovrebbe restituire un valore basato sul valore de
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var fixedValue = 4;
|
||||
let fixedValue = 4;
|
||||
|
||||
function incrementer () {
|
||||
function incrementer() {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ function incrementer () {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var fixedValue = 4
|
||||
let fixedValue = 4
|
||||
|
||||
function incrementer() {
|
||||
return fixedValue + 1
|
||||
|
@ -13,8 +13,8 @@ Il metodo `join` viene utilizzato per unire gli elementi di un array per creare
|
||||
Ecco un esempio:
|
||||
|
||||
```js
|
||||
var arr = ["Hello", "World"];
|
||||
var str = arr.join(" ");
|
||||
const arr = ["Hello", "World"];
|
||||
const str = arr.join(" ");
|
||||
```
|
||||
|
||||
`str` conterrà la stringa `Hello World`.
|
||||
@ -76,6 +76,7 @@ function sentensify(str) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
sentensify("May-the-force-be-with-you");
|
||||
```
|
||||
|
||||
@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you");
|
||||
|
||||
```js
|
||||
function sentensify(str) {
|
||||
// Only change code below this line
|
||||
return str.split(/\W/).join(' ');
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
nonMutatingConcat(first, second);
|
||||
```
|
||||
|
||||
@ -69,11 +70,8 @@ nonMutatingConcat(first, second);
|
||||
|
||||
```js
|
||||
function nonMutatingConcat(original, attach) {
|
||||
// Only change code below this line
|
||||
return original.concat(attach);
|
||||
// Only change code above this line
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
nonMutatingConcat(first, second);
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
```
|
||||
|
@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g));
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myMap = function(callback) {
|
||||
var newArray = [];
|
||||
const newArray = [];
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myMap(function(item) {
|
||||
const new_s = s.myMap(function(item) {
|
||||
return item * 2;
|
||||
});
|
||||
```
|
||||
@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myMap = function(callback) {
|
||||
var newArray = [];
|
||||
// Only change code below this line
|
||||
for (var elem of this) {
|
||||
const newArray = [];
|
||||
for (const elem of this) {
|
||||
newArray.push(callback(elem));
|
||||
}
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myMap(function(item) {
|
||||
const new_s = s.myMap(function(item) {
|
||||
return item * 2;
|
||||
});
|
||||
```
|
||||
|
@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g));
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myFilter = function(callback) {
|
||||
// Only change code below this line
|
||||
var newArray = [];
|
||||
const newArray = [];
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myFilter(function(item) {
|
||||
const new_s = s.myFilter(function(item) {
|
||||
return item % 2 === 1;
|
||||
});
|
||||
```
|
||||
@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myFilter = function(callback) {
|
||||
var newArray = [];
|
||||
// Only change code below this line
|
||||
const newArray = [];
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
if (callback(this[i])) newArray.push(this[i]);
|
||||
}
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myFilter(function(item) {
|
||||
const new_s = s.myFilter(function(item) {
|
||||
return item % 2 === 1;
|
||||
});
|
||||
```
|
||||
|
@ -35,7 +35,7 @@ curried(1)(2)
|
||||
Questo sarà utile nel tuo programma se non sarai in grado di fornire tutti gli argomenti ad una funzione in una sola volta. Potrai salvare ogni chiamata di funzione in una variabile, che manterrà il riferimento alla funzione restituita, che prenderà l'argomento successivo quando sarà disponibile. Ecco un esempio usando la funzione curried dell'esempio visto sopra:
|
||||
|
||||
```js
|
||||
var funcForY = curried(1);
|
||||
const funcForY = curried(1);
|
||||
console.log(funcForY(2)); // 3
|
||||
```
|
||||
|
||||
@ -45,7 +45,8 @@ Allo stesso modo, <dfn>l'applicazione parziale</dfn> può essere descritta come
|
||||
function impartial(x, y, z) {
|
||||
return x + y + z;
|
||||
}
|
||||
var partialFn = impartial.bind(this, 1, 2);
|
||||
|
||||
const partialFn = impartial.bind(this, 1, 2);
|
||||
partialFn(10); // 13
|
||||
```
|
||||
|
||||
@ -90,6 +91,7 @@ function add(x) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
add(10)(20)(30);
|
||||
```
|
||||
|
||||
|
@ -53,10 +53,10 @@ assert(__newValue === 5);
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var fixedValue = 4;
|
||||
let fixedValue = 4;
|
||||
|
||||
// Only change code below this line
|
||||
function incrementer () {
|
||||
function incrementer() {
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
@ -66,15 +66,9 @@ function incrementer () {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var fixedValue = 4;
|
||||
let fixedValue = 4;
|
||||
|
||||
// Only change code below this line
|
||||
function incrementer (fixedValue) {
|
||||
function incrementer(fixedValue) {
|
||||
return fixedValue + 1;
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
@ -10,7 +10,7 @@ dashedName: refactor-global-variables-out-of-functions
|
||||
|
||||
Finora abbiamo visto due principi distinti per la programmazione funzionale:
|
||||
|
||||
1) Non modificare una variabile o un oggetto - se necessario creare nuove variabili e oggetti e restituirli da una funzione. Suggerimento: usando qualcosa come `var newArr = arrVar`, dove `arrVar` è un array, creerai semplicemente un riferimento alla variabile esistente e non una copia. Quindi cambiando un valore in `newArr` cambierà anche il valore in `arrVar`.
|
||||
1) Non modificare una variabile o un oggetto - se necessario creare nuove variabili e oggetti e restituirli da una funzione. Suggerimento: usando qualcosa come `const newArr = arrVar`, dove `arrVar` è un array, creerai semplicemente un riferimento alla variabile esistente e non una copia. Quindi cambiando un valore in `newArr` cambierà anche il valore in `arrVar`.
|
||||
|
||||
2) Dichiarare i parametri della funzione - qualsiasi calcolo all'interno di una funzione deve dipendere solo dagli argomenti passati alla funzione, e non da qualsiasi oggetto o variabile globale.
|
||||
|
||||
@ -86,7 +86,7 @@ assert(
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
|
||||
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
|
||||
|
||||
// Change code below this line
|
||||
function add (bookName) {
|
||||
@ -99,7 +99,7 @@ function add (bookName) {
|
||||
|
||||
// Change code below this line
|
||||
function remove (bookName) {
|
||||
var book_index = bookList.indexOf(bookName);
|
||||
const book_index = bookList.indexOf(bookName);
|
||||
if (book_index >= 0) {
|
||||
|
||||
bookList.splice(book_index, 1);
|
||||
@ -109,9 +109,9 @@ function remove (bookName) {
|
||||
}
|
||||
}
|
||||
|
||||
var newBookList = add(bookList, 'A Brief History of Time');
|
||||
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
|
||||
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
|
||||
const newBookList = add(bookList, 'A Brief History of Time');
|
||||
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
|
||||
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
|
||||
|
||||
console.log(bookList);
|
||||
```
|
||||
@ -120,13 +120,13 @@ console.log(bookList);
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
|
||||
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
|
||||
|
||||
function add (bookList, bookName) {
|
||||
function add(bookList, bookName) {
|
||||
return [...bookList, bookName];
|
||||
}
|
||||
|
||||
function remove (bookList, bookName) {
|
||||
function remove(bookList, bookName) {
|
||||
const bookListCopy = [...bookList];
|
||||
const bookNameIndex = bookList.indexOf(bookName);
|
||||
if (bookNameIndex >= 0) {
|
||||
@ -135,7 +135,7 @@ function remove (bookList, bookName) {
|
||||
return bookListCopy;
|
||||
}
|
||||
|
||||
var newBookList = add(bookList, 'A Brief History of Time');
|
||||
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
|
||||
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
|
||||
const newBookList = add(bookList, 'A Brief History of Time');
|
||||
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
|
||||
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
|
||||
```
|
||||
|
@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice
|
||||
Un'operazione che si fa comunemente lavorando con gli array è quella di rimuovere degli elemento mantenendo il resto dell'array. A questo scopo JavaScript offre il metodo `splice`, che richiede degli argomenti per la posizione (indice) di dove iniziare a rimuovere gli elementi, e per il numero di elementi da rimuovere. Se il secondo argomento non è fornito, il comportamento predefinito è quello di rimuovere gli elementi fino alla fine. Tuttavia, il metodo `splice` muta l'array originale su cui viene chiamato. Ecco un esempio:
|
||||
|
||||
```js
|
||||
var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
cities.splice(3, 1);
|
||||
```
|
||||
|
||||
@ -69,7 +69,8 @@ function nonMutatingSplice(cities) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
|
||||
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
nonMutatingSplice(inputCities);
|
||||
```
|
||||
|
||||
@ -77,10 +78,7 @@ nonMutatingSplice(inputCities);
|
||||
|
||||
```js
|
||||
function nonMutatingSplice(cities) {
|
||||
// Only change code below this line
|
||||
return cities.slice(0,3);
|
||||
// Only change code above this line
|
||||
}
|
||||
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
nonMutatingSplice(inputCities);
|
||||
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
```
|
||||
|
@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) ===
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var globalArray = [5, 6, 3, 2, 9];
|
||||
const globalArray = [5, 6, 3, 2, 9];
|
||||
|
||||
function nonMutatingSort(arr) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
nonMutatingSort(globalArray);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var globalArray = [5, 6, 3, 2, 9];
|
||||
const globalArray = [5, 6, 3, 2, 9];
|
||||
function nonMutatingSort(arr) {
|
||||
// Only change code below this line
|
||||
return [].concat(arr).sort((a,b) => a-b);
|
||||
// Only change code above this line
|
||||
}
|
||||
nonMutatingSort(globalArray);
|
||||
```
|
||||
|
@ -13,8 +13,8 @@ Il metodo `slice` restituisce una copia di alcuni elementi di un array. Può pre
|
||||
Ecco un esempio:
|
||||
|
||||
```js
|
||||
var arr = ["Cat", "Dog", "Tiger", "Zebra"];
|
||||
var newArray = arr.slice(1, 3);
|
||||
const arr = ["Cat", "Dog", "Tiger", "Zebra"];
|
||||
const newArray = arr.slice(1, 3);
|
||||
```
|
||||
|
||||
`newArray` avrà il valore `["Dog", "Tiger"]`.
|
||||
@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
|
||||
const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
sliceArray(inputAnim, 1, 3);
|
||||
```
|
||||
|
||||
@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3);
|
||||
|
||||
```js
|
||||
function sliceArray(anim, beginSlice, endSlice) {
|
||||
// Only change code below this line
|
||||
return anim.slice(beginSlice, endSlice)
|
||||
// Only change code above this line
|
||||
return anim.slice(beginSlice, endSlice);
|
||||
}
|
||||
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
sliceArray(inputAnim, 1, 3);
|
||||
const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
```
|
||||
|
@ -18,6 +18,7 @@ function ascendingOrder(arr) {
|
||||
return a - b;
|
||||
});
|
||||
}
|
||||
|
||||
ascendingOrder([1, 5, 2, 3, 4]);
|
||||
```
|
||||
|
||||
@ -29,6 +30,7 @@ function reverseAlpha(arr) {
|
||||
return a === b ? 0 : a < b ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
reverseAlpha(['l', 'h', 'z', 'b', 's']);
|
||||
```
|
||||
|
||||
@ -86,6 +88,7 @@ function alphabeticalOrder(arr) {
|
||||
return arr
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
```
|
||||
|
||||
@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
|
||||
```js
|
||||
function alphabeticalOrder(arr) {
|
||||
// Only change code below this line
|
||||
return arr.sort();
|
||||
// Only change code above this line
|
||||
}
|
||||
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
```
|
||||
|
@ -13,11 +13,11 @@ Il metodo `split` divide una stringa in un array di stringhe. Esso richiede un a
|
||||
Ecco un esempio che divide una stringa in base agli spazi, poi un altro in base alle cifre facendo uso di un'espressione regolare:
|
||||
|
||||
```js
|
||||
var str = "Hello World";
|
||||
var bySpace = str.split(" ");
|
||||
const str = "Hello World";
|
||||
const bySpace = str.split(" ");
|
||||
|
||||
var otherString = "How9are7you2today";
|
||||
var byDigits = otherString.split(/\d/);
|
||||
const otherString = "How9are7you2today";
|
||||
const byDigits = otherString.split(/\d/);
|
||||
```
|
||||
|
||||
`bySpace` avrà il valore `["Hello", "World"]` e `byDigits` avrà il valore `["How", "are", "you", "today"]`.
|
||||
@ -74,6 +74,7 @@ function splitify(str) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
splitify("Hello World,I-am code");
|
||||
```
|
||||
|
||||
@ -81,8 +82,6 @@ splitify("Hello World,I-am code");
|
||||
|
||||
```js
|
||||
function splitify(str) {
|
||||
// Only change code below this line
|
||||
return str.split(/\W/);
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [
|
||||
|
||||
```js
|
||||
// tabs is an array of titles of each site open within the window
|
||||
var Window = function(tabs) {
|
||||
const Window = function(tabs) {
|
||||
this.tabs = tabs; // We keep a record of the array inside the object
|
||||
};
|
||||
|
||||
// When you join two windows into one window
|
||||
Window.prototype.join = function (otherWindow) {
|
||||
Window.prototype.join = function(otherWindow) {
|
||||
this.tabs = this.tabs.concat(otherWindow.tabs);
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you open a new tab at the end
|
||||
Window.prototype.tabOpen = function (tab) {
|
||||
Window.prototype.tabOpen = function(tab) {
|
||||
this.tabs.push('new tab'); // Let's open a new tab for now
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you close a tab
|
||||
Window.prototype.tabClose = function (index) {
|
||||
Window.prototype.tabClose = function(index) {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
|
||||
var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
|
||||
const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
|
||||
const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
|
||||
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
|
||||
|
||||
@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) {
|
||||
};
|
||||
|
||||
// Let's create three browser windows
|
||||
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
|
||||
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
|
||||
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
|
||||
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
|
||||
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
|
||||
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
|
||||
|
||||
// Now perform the tab opening, closing, and other operations
|
||||
var finalTabs = socialWindow
|
||||
const finalTabs = socialWindow
|
||||
.tabOpen() // Open a new tab for cat memes
|
||||
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
|
||||
.join(workWindow.tabClose(1).tabOpen());
|
||||
@ -106,40 +106,34 @@ console.log(finalTabs.tabs);
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// tabs is an array of titles of each site open within the window
|
||||
var Window = function(tabs) {
|
||||
this.tabs = tabs; // We keep a record of the array inside the object
|
||||
const Window = function(tabs) {
|
||||
this.tabs = tabs;
|
||||
};
|
||||
|
||||
// When you join two windows into one window
|
||||
Window.prototype.join = function (otherWindow) {
|
||||
Window.prototype.join = function(otherWindow) {
|
||||
this.tabs = this.tabs.concat(otherWindow.tabs);
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you open a new tab at the end
|
||||
Window.prototype.tabOpen = function (tab) {
|
||||
this.tabs.push('new tab'); // Let's open a new tab for now
|
||||
Window.prototype.tabOpen = function(tab) {
|
||||
this.tabs.push('new tab');
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you close a tab
|
||||
Window.prototype.tabClose = function (index) {
|
||||
var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab
|
||||
var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab
|
||||
Window.prototype.tabClose = function(index) {
|
||||
const tabsBeforeIndex = this.tabs.slice(0, index);
|
||||
const tabsAfterIndex = this.tabs.slice(index + 1);
|
||||
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex);
|
||||
return this;
|
||||
};
|
||||
|
||||
// Let's create three browser windows
|
||||
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
|
||||
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
|
||||
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
|
||||
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']);
|
||||
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']);
|
||||
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']);
|
||||
|
||||
// Now perform the tab opening, closing, and other operations
|
||||
var finalTabs = socialWindow
|
||||
.tabOpen() // Open a new tab for cat memes
|
||||
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
|
||||
const finalTabs = socialWindow
|
||||
.tabOpen()
|
||||
.join(videoWindow.tabClose(2))
|
||||
.join(workWindow.tabClose(1).tabOpen());
|
||||
```
|
||||
|
@ -13,7 +13,8 @@ Il metodo `every` funziona con gli array per controllare se *ogni* elemento supe
|
||||
Ad esempio, il seguente codice controllerà se ogni elemento nell'array `numbers` è inferiore a 10:
|
||||
|
||||
```js
|
||||
var numbers = [1, 5, 8, 0, 10, 11];
|
||||
const numbers = [1, 5, 8, 0, 10, 11];
|
||||
|
||||
numbers.every(function(currentValue) {
|
||||
return currentValue < 10;
|
||||
});
|
||||
@ -62,6 +63,7 @@ function checkPositive(arr) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
||||
@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]);
|
||||
|
||||
```js
|
||||
function checkPositive(arr) {
|
||||
// Only change code below this line
|
||||
return arr.every(num => num > 0);
|
||||
// Only change code above this line
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
@ -55,7 +55,7 @@ Il tuo codice non dovrebbe utilizzare un ciclo `for`.
|
||||
assert(!code.match(/for\s*?\([\s\S]*?\)/g));
|
||||
```
|
||||
|
||||
`filteredList` dovrebbe essere uguale a `[{"title": "Inception","rating": "8.8"},{"title": "Interstellar","rating": "8.6"},{"title": "The Dark Knight","rating": "9.0"},{"title": "Batman Begins","rating": "8.3"}]`.
|
||||
`filteredList` dovrebbe essere uguale a `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"}, {"title": "Batman Begins", "rating": "8.3"}]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(filteredList, [
|
||||
@ -72,7 +72,7 @@ assert.deepEqual(filteredList, [
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -187,7 +187,7 @@ var watchList = [
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var filteredList;
|
||||
const filteredList = "";
|
||||
|
||||
// Only change code above this line
|
||||
|
||||
@ -197,8 +197,7 @@ console.log(filteredList);
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -311,7 +310,5 @@ var watchList = [
|
||||
}
|
||||
];
|
||||
|
||||
// Only change code below this line
|
||||
let filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
|
||||
// Only change code above this line
|
||||
const filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
|
||||
```
|
||||
|
@ -61,7 +61,7 @@ Il tuo codice dovrebbe utilizzare il metodo `map`.
|
||||
assert(code.match(/\.map/g));
|
||||
```
|
||||
|
||||
`ratings` dovrebbe essere uguale a `[{"title":"Inception","rating":"8.8"},{"title":"Interstellar","rating":"8.6"},{"title":"The Dark Knight","rating":"9.0"},{"title":"Batman Begins","rating":"8.3"},{"title":"Avatar","rating":"7.9"}]`.
|
||||
`ratings` dovrebbe essere uguale a `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"},{"title": "Batman Begins", "rating": "8.3"}, {"title": "Avatar", "rating": "7.9"}]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ratings, [
|
||||
@ -79,7 +79,7 @@ assert.deepEqual(ratings, [
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -194,9 +194,9 @@ var watchList = [
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var ratings = [];
|
||||
for(var i=0; i < watchList.length; i++){
|
||||
ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]});
|
||||
const ratings = [];
|
||||
for (let i = 0; i < watchList.length; i++) {
|
||||
ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]});
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
@ -207,8 +207,7 @@ console.log(JSON.stringify(ratings));
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -321,7 +320,7 @@ var watchList = [
|
||||
}
|
||||
];
|
||||
|
||||
var ratings = watchList.map(function(movie) {
|
||||
const ratings = watchList.map(function(movie) {
|
||||
return {
|
||||
title: movie["Title"],
|
||||
rating: movie["imdbRating"]
|
||||
|
@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55);
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -206,22 +206,22 @@ var watchList = [
|
||||
}
|
||||
];
|
||||
|
||||
function getRating(watchList){
|
||||
function getRating(watchList) {
|
||||
// Only change code below this line
|
||||
var averageRating;
|
||||
let averageRating;
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return averageRating;
|
||||
}
|
||||
|
||||
console.log(getRating(watchList));
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -334,8 +334,8 @@ var watchList = [
|
||||
}
|
||||
];
|
||||
|
||||
function getRating(watchList){
|
||||
var averageRating;
|
||||
function getRating(watchList) {
|
||||
let averageRating;
|
||||
const rating = watchList
|
||||
.filter(obj => obj.Director === "Christopher Nolan")
|
||||
.map(obj => Number(obj.imdbRating));
|
||||
|
@ -13,7 +13,8 @@ Il metodo `some` funziona con gli array per verificare se *un qualunque* element
|
||||
Ad esempio, il seguente codice controllerà se almeno un elemento nell'array `numbers` è inferiore a 10:
|
||||
|
||||
```js
|
||||
var numbers = [10, 50, 8, 220, 110, 11];
|
||||
const numbers = [10, 50, 8, 220, 110, 11];
|
||||
|
||||
numbers.some(function(currentValue) {
|
||||
return currentValue < 10;
|
||||
});
|
||||
@ -62,6 +63,7 @@ function checkPositive(arr) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
||||
@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]);
|
||||
|
||||
```js
|
||||
function checkPositive(arr) {
|
||||
// Only change code below this line
|
||||
return arr.some(elem => elem > 0);
|
||||
// Only change code above this line
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
Reference in New Issue
Block a user