From f5b06fdecfea90506e12fcca24c63b74428d70c7 Mon Sep 17 00:00:00 2001 From: Josh Moncrieff Date: Sun, 18 Aug 2019 14:14:49 +1000 Subject: [PATCH 1/4] docs(array): grammar --- book/content/part02/array.asc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/content/part02/array.asc b/book/content/part02/array.asc index b301f7cf..5d177405 100644 --- a/book/content/part02/array.asc +++ b/book/content/part02/array.asc @@ -17,7 +17,7 @@ TIP: Strings are a collection of Unicode characters and most of the array concep .Fixed vs. Dynamic Size Arrays **** -Some programming languages have fixed size arrays like Java and C++. Fixed size arrays might be a hassle when your collection gets full, and you have to create a new one with a bigger size. For that, those programming languages also have built-in dynamic arrays: we have `vector` in C++ and `ArrayList` in Java. Dynamic programming languages like JavaScript, Ruby, Python use dynamic arrays by default. +Some programming languages have fixed size arrays like Java and C++. Fixed size arrays might be a hassle when your collection gets full, and you have to create a new one with a bigger size. For that, those programming languages also have built-in dynamic arrays: we have `vector` in C++ and `ArrayList` in Java. Dynamic programming languages, like JavaScript, Ruby, and Python, use dynamic arrays by default. **** Arrays look like this: From 85a5f4889a4c79bb92ebb74bfd3f2a7c8bc4553e Mon Sep 17 00:00:00 2001 From: Josh Moncrieff Date: Sun, 18 Aug 2019 14:27:20 +1000 Subject: [PATCH 2/4] docs(array): update grammar, adjust style for consistency and clarity --- book/content/part02/array.asc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/content/part02/array.asc b/book/content/part02/array.asc index 5d177405..544b7791 100644 --- a/book/content/part02/array.asc +++ b/book/content/part02/array.asc @@ -29,15 +29,15 @@ Arrays are a sequential collection of elements that can be accessed randomly usi ==== Insertion -Arrays are built-in into most languages. Inserting an element is simple; you can either add them on creation time or after initialization. Below you can find an example for both cases: +Arrays are a built-in part of most languages. In JavaScript, populating an array is simple; elements can either be added at the time of initialization, or after. Below you can find an example of both cases: .Inserting elements into an array [source, javascript] ---- -// (1) Add elements at the creation time: +// (1) Initialize an array pre-populated with elements: const array = [2, 5, 1, 9, 6, 7]; -// (2) initialize an empty array and add values later +// (2) initialize an empty array and add elements later const array2 = []; array2[3] = 1; array2[100] = 2; From 79022cab089a555d3c7543ebf7f41e36155fff15 Mon Sep 17 00:00:00 2001 From: Josh Moncrieff Date: Sun, 18 Aug 2019 14:35:15 +1000 Subject: [PATCH 3/4] docs(array): combine example blocks into one for consistency --- book/content/part02/array.asc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/book/content/part02/array.asc b/book/content/part02/array.asc index 544b7791..8cbe57ca 100644 --- a/book/content/part02/array.asc +++ b/book/content/part02/array.asc @@ -41,18 +41,12 @@ const array = [2, 5, 1, 9, 6, 7]; const array2 = []; array2[3] = 1; array2[100] = 2; -array2 // [empty × 3, 1, empty × 96, 2] ----- - -Using the index, you can replace whatever value you want. Also, you don't have to add items next to each other. The size of the array will dynamically expand to accommodate the data. You can reference values in whatever index you like index 3 or even 100! In the `array2` we inserted 2 numbers, but the length is 101, and there are 99 empty spaces. -[source, javascript] ----- console.log(array2.length); // 101 console.log(array2); // [empty × 3, 1, empty × 96, 2] ---- - +Using the index, you can replace whatever value you want. Also, you don't have to add items next to each other. The size of the array will dynamically expand to accommodate the data. You can reference values in whatever index you like index 3 or even 100! In the `array2` we inserted 2 numbers, but the length is 101, and there are 99 empty spaces. The runtime for inserting elements using index is always is constant: _O(1)_. ===== Inserting at the beginning of the array From 76c2ca17eb1d466e66c43df449d8be2829c72f1a Mon Sep 17 00:00:00 2001 From: Josh Moncrieff Date: Sun, 18 Aug 2019 14:47:30 +1000 Subject: [PATCH 4/4] docs(array): reword for clarity and tone --- book/content/part02/array.asc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/content/part02/array.asc b/book/content/part02/array.asc index 8cbe57ca..5ad54b9e 100644 --- a/book/content/part02/array.asc +++ b/book/content/part02/array.asc @@ -29,7 +29,7 @@ Arrays are a sequential collection of elements that can be accessed randomly usi ==== Insertion -Arrays are a built-in part of most languages. In JavaScript, populating an array is simple; elements can either be added at the time of initialization, or after. Below you can find an example of both cases: +Arrays are a built-in part of most languages. In JavaScript, populating an array is simple; elements can either be added at the time of initialization, or after. See below for examples of both cases: .Inserting elements into an array [source, javascript] @@ -46,7 +46,7 @@ console.log(array2.length); // 101 console.log(array2); // [empty × 3, 1, empty × 96, 2] ---- -Using the index, you can replace whatever value you want. Also, you don't have to add items next to each other. The size of the array will dynamically expand to accommodate the data. You can reference values in whatever index you like index 3 or even 100! In the `array2` we inserted 2 numbers, but the length is 101, and there are 99 empty spaces. +Using the index, you can access and/or modify any value you choose. Also, you can reference values in any index you choose. The size of the array will dynamically expand to accommodate the data. For example, in `array2` 2 numbers have been inserted, but the length is 101, and there are 99 empty spaces. The runtime for inserting elements using index is always is constant: _O(1)_. ===== Inserting at the beginning of the array