Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
6d12e35
typo
maurodibert Jan 23, 2019
b7f40bd
Fix typo loose to lose
richardzhanghub Jan 23, 2019
30d62b7
solution outside the tutorial
maurodibert Jan 24, 2019
308179f
Merge pull request #755 from maurodibert/patch-22
iliakan Jan 24, 2019
eb3f7f4
Merge pull request #752 from richardzhang2/patch-1
iliakan Jan 24, 2019
028b80c
Merge pull request #750 from maurodibert/patch-20
iliakan Jan 24, 2019
9d4f6ed
solution out of the tutorial
maurodibert Jan 24, 2019
f725537
Update article about WeakMap's delete function
GarciaPL Jan 25, 2019
704f817
fix: replace a non-native expression
TomSssM Jan 26, 2019
0eede58
Update article.md
totize Jan 27, 2019
801fa33
update /13-switch/article.md
Jan 27, 2019
fce9639
Update /14-function-basics/article.md
Jan 27, 2019
f7fbe4f
Merge pull request #762 from thisLinda/patch-2
iliakan Jan 27, 2019
4a200da
Merge pull request #761 from thisLinda/patch-1
iliakan Jan 27, 2019
5bb77e1
Merge pull request #760 from totize/patch-2
iliakan Jan 27, 2019
04fa38a
Merge pull request #758 from TomSssM/patch-1
iliakan Jan 27, 2019
58b7d72
Merge pull request #757 from GarciaPL/patch-1
iliakan Jan 27, 2019
e774c7c
Merge pull request #756 from maurodibert/patch-22
iliakan Jan 27, 2019
3db5a1c
Fixed wording
simmayor Jan 28, 2019
89cdf0a
typo "brackets" to "parentheses"
l1un Jan 29, 2019
2862f91
Merge pull request #765 from simmayor/01-js-02-first-14-function
iliakan Jan 29, 2019
38e1bb5
Merge pull request #767 from 11un/patch-10
iliakan Jan 29, 2019
058029a
typo its->it's
dagolinuxoid Jan 29, 2019
88f2c5f
Update task.md
totize Jan 29, 2019
a5425e7
add solution with fixed indentation
l1un Jan 29, 2019
7a14b00
Ordering solution
maurodibert Jan 31, 2019
c775348
Update article.md
Jan 31, 2019
07550ef
change wording: "brackets" to "parentheses"
l1un Feb 1, 2019
758c3d6
Merge pull request #770 from dagolinuxoid/patch-2
iliakan Feb 1, 2019
e458055
Merge pull request #780 from 11un/patch-11
iliakan Feb 1, 2019
6a3ca84
Merge pull request #779 from ope-oguntoye/patch-1
iliakan Feb 1, 2019
55220cc
fix
iliakan Feb 1, 2019
0510f30
Merge pull request #775 from maurodibert/patch-24
iliakan Feb 1, 2019
1c4fb87
Revert "Merge pull request #775 from maurodibert/patch-24"
iliakan Feb 1, 2019
c99d828
Merge pull request #771 from totize/patch-3
iliakan Feb 1, 2019
c4ecba5
Merge pull request #772 from 11un/patch-9-fix-indent
iliakan Feb 1, 2019
161eec6
change "brackets" to "parentheses"
l1un Feb 2, 2019
3a6d70b
Merge pull request #781 from 11un/patch-12
iliakan Feb 2, 2019
46c88b4
"In practice we meet it very often." is wrong.
AxonDragonScale Feb 3, 2019
37f46bd
typo / wording "remnant"
l1un Feb 4, 2019
1864c1c
update
Darryl1702 Feb 5, 2019
2e05457
Type in editable div task
DarkPurple141 Feb 5, 2019
1591c82
update
Darryl1702 Feb 6, 2019
6246ac2
Misleading comments
varunthefalcon Feb 6, 2019
cc065a8
Merge pull request #782 from AxonDragonScale/patch-1
iliakan Feb 6, 2019
b526e6b
Merge pull request #784 from 11un/patch-13
iliakan Feb 6, 2019
bbe8e48
Merge pull request #785 from Ghost-017/patch-8
iliakan Feb 6, 2019
19adf7c
Merge pull request #786 from DarkPurple141/patch-1
iliakan Feb 6, 2019
f07d4a0
Merge pull request #787 from Ghost-017/patch-9
iliakan Feb 6, 2019
d11abce
Merge pull request #788 from varunthefalcon/patch-1
iliakan Feb 6, 2019
5af3e71
update
Darryl1702 Feb 7, 2019
6bf2aec
Fix typo
MikeTaylor Feb 8, 2019
ec9a99d
Update article.md
iliakan Feb 9, 2019
b064eda
Fix broken link of issues in README file.
TrueMoein Feb 10, 2019
29d2562
Merge pull request #791 from MikeTaylor/patch-1
iliakan Feb 10, 2019
09bc924
Merge pull request #792 from TrueMoein/fix-broken-link
iliakan Feb 10, 2019
ae89ffb
Edit error in code snippet ## HTTP-headers
vkv0220 Feb 11, 2019
4b4df26
added us so the sentence makes sense
weswhite Feb 12, 2019
ef3f4f2
Update article.md
weswhite Feb 12, 2019
9dd4746
Update article.md
weswhite Feb 12, 2019
a86e220
Update article.md
weswhite Feb 12, 2019
175e159
Update article.md
CyberMew Feb 13, 2019
7e71d1f
Update article.md
CyberMew Feb 13, 2019
e95e0ba
Update article.md
CyberMew Feb 13, 2019
bddc40c
Update solution.js
CyberMew Feb 13, 2019
9a21e07
Merge pull request #802 from CyberMew/patch-4
iliakan Feb 13, 2019
de5d580
Merge pull request #801 from CyberMew/patch-3
iliakan Feb 13, 2019
05e1e26
Merge pull request #800 from CyberMew/patch-1
iliakan Feb 13, 2019
5c61bed
Merge pull request #799 from CyberMew/patch-2
iliakan Feb 13, 2019
6de8c3c
Merge pull request #795 from weswhite/master
iliakan Feb 13, 2019
469df8c
Merge pull request #794 from vkv0220/patch-1
iliakan Feb 13, 2019
c089ff7
Merge pull request #790 from Ghost-017/patch-1
iliakan Feb 13, 2019
1419ecb
Added a missing comma
adamcnaglich Feb 13, 2019
0de525c
Update article.md
CyberMew Feb 14, 2019
5fbfb02
Update article.md
CyberMew Feb 14, 2019
769ae74
Merge pull request #807 from CyberMew/patch-7
iliakan Feb 14, 2019
0d4ed3a
Merge pull request #805 from CyberMew/patch-5
iliakan Feb 14, 2019
a2392f3
Merge pull request #803 from adamcnaglich/patch-1
iliakan Feb 14, 2019
7f9c2db
Update README.md
iliakan Feb 15, 2019
de96eda
Update README.md
iliakan Feb 15, 2019
1b2d3e8
Update README.md
iliakan Feb 15, 2019
114c482
typo + add link to relevant chapter
l1un Feb 15, 2019
4505bda
Update article.md
maurodibert Feb 16, 2019
4d1bd71
grammer fixes
Darryl1702 Feb 17, 2019
b2c478e
Update article.md
Evoniuk Feb 19, 2019
ac2e10c
Fix variable name mistake in modifying-document
papb Feb 20, 2019
2f34acb
Merge pull request #814 from papb/patch-1
iliakan Feb 21, 2019
6a02381
Merge pull request #813 from Evoniuk/patch-1
iliakan Feb 21, 2019
ba34f5e
Merge pull request #812 from Ghost-017/patch-2
iliakan Feb 21, 2019
1157a95
Merge pull request #811 from maurodibert/patch-29
iliakan Feb 21, 2019
afc268c
Merge pull request #810 from 11un/patch-14
iliakan Feb 21, 2019
b180a94
Update solution.md
iliakan Feb 21, 2019
360be9e
fix
iliakan Feb 21, 2019
408ba7d
make sure a solution always shows up, use "demo" if exists
iliakan Feb 21, 2019
68109cf
Update task.md
vasilevx Feb 21, 2019
eeca775
missing word
Evoniuk Feb 24, 2019
5d42d8b
Remove redundant 'if'
hosmanadam Feb 25, 2019
57ef354
typo "if" --> "it"
l1un Feb 28, 2019
7c97edc
typo
maurodibert Mar 2, 2019
bf779f9
Merge pull request #824 from maurodibert/patch-33
iliakan Mar 2, 2019
f675e33
Merge pull request #821 from 11un/patch-17
iliakan Mar 2, 2019
148b389
Merge pull request #820 from hosmanadam/patch-1
iliakan Mar 2, 2019
df2f013
Merge pull request #817 from Evoniuk/patch-2
iliakan Mar 2, 2019
33b67f0
Merge pull request #815 from vasilevx/patch-1
iliakan Mar 2, 2019
b8f6d96
modules: draft
iliakan Feb 26, 2019
a16814a
refactoring, modules
iliakan Feb 26, 2019
9936f9c
generator draft
iliakan Feb 27, 2019
be9c5a7
re-export pictures
iliakan Feb 27, 2019
2ee2751
refactor promise, geneerators, global object
iliakan Feb 27, 2019
1369332
async generators
iliakan Feb 28, 2019
65184ed
regexp draft
iliakan Mar 1, 2019
7888439
regexp draft
iliakan Mar 2, 2019
d043b11
merge prs
iliakan Mar 2, 2019
eefd392
minor
iliakan Mar 2, 2019
77655a2
minor
iliakan Mar 2, 2019
32120fb
import.meta
iliakan Mar 2, 2019
a0c0734
import.meta
iliakan Mar 2, 2019
1373f61
refactor classes, add private, minor fixes
iliakan Mar 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified 1-js/01-getting-started/1-intro/limitations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/01-getting-started/1-intro/limitations@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/02-structure/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The first thing we'll study is the building blocks of code.

Statements are syntax constructs and commands that perform actions.

We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello world!".
We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!".

We can have as many statements in our code as we want. Statements can be separated with a semicolon.

Expand Down
Binary file modified 1-js/02-first-steps/04-variables/variable-change.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/02-first-steps/04-variables/variable-change@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/02-first-steps/04-variables/variable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/02-first-steps/04-variables/variable@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/13-switch/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Let's emphasize that the equality check is always strict. The values must be of
For example, let's consider the code:

```js run
let arg = prompt("Enter a value?")
let arg = prompt("Enter a value?");
switch (arg) {
case '0':
case '1':
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/14-function-basics/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Variables declared outside of any function, such as the outer `userName` in the

Global variables are visible from any function (unless shadowed by locals).

Usually, a function declares all variables specific to its task. Global variables only store project-level data, so when it's important that these variables are accesible from anywhere. Modern code has few or no globals. Most variables reside in their functions.
Usually, a function declares all variables specific to its task. Global variables only store project-level data, and it's important that these variables are accessible from anywhere. Modern code has few or no globals. Most variables reside in their functions.
```

## Parameters
Expand Down
Binary file modified 1-js/02-first-steps/14-function-basics/function_basics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/02-first-steps/14-function-basics/function_basics@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/03-code-quality/02-coding-style/code-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/03-code-quality/02-coding-style/code-style@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/03-code-quality/02-coding-style/figure-bracket-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/03-code-quality/02-coding-style/figure-bracket-style@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions 1-js/03-code-quality/04-ninja-code/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ While choosing a name try to use the most abstract word. Like `obj`, `data`, `va

Give them a try. A young initiate may wonder -- are such names really useful for a ninja? Indeed, they are!

Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all! And will ultimately fail to alter your well-thought code.
Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, they'll be surprised to see that there's actually no information at all! And will ultimately fail to alter your well-thought code.

The value type is easy to find out by debugging. But what's the meaning of the variable? Which string/number does it store?

Expand Down Expand Up @@ -153,7 +153,7 @@ function ninjaFunction(elem) {
}
```

A fellow programmer who wants to work with `elem` in the second half of the function will be surprised... Only during the debugging, after examining the code they will find out that he's working with a clone!
A fellow programmer who wants to work with `elem` in the second half of the function will be surprised... Only during the debugging, after examining the code they will find out that they're working with a clone!

Seen in code regularly. Deadly effective even against an experienced ninja.

Expand Down Expand Up @@ -197,7 +197,7 @@ function render() {

A programmer who jumps inside the `render` will probably fail to notice that there's a local `user` shadowing the outer one.

Then he'll try to work with `user` assuming that it's the external variable, the result of `authenticateUser()`... The trap is sprung! Hello, debugger...
Then they'll try to work with `user` assuming that it's the external variable, the result of `authenticateUser()`... The trap is sprung! Hello, debugger...


## Side-effects everywhere!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function isEmpty(obj) {
for (let key in obj) {
// if the loop has started, there is a prorty
// if the loop has started, there is a property
return false;
}
return true;
}
}
9 changes: 0 additions & 9 deletions 1-js/04-object-basics/01-object/3-is-empty/solution.md
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
Just loop over the object and `return false` immediately if there's at least one property.

```js
function isEmpty(obj) {
for (let key in obj) {
return false;
}
return true;
}
```
19 changes: 0 additions & 19 deletions 1-js/04-object-basics/01-object/8-multiply-numeric/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
``` js run

// before the call
let menu = {
width: 200,
height: 300,
title: "My menu"
};

function multiplyNumeric(obj) {
for (let key in obj) {
if (typeof obj[key] == 'number') {
obj[key] *= 2;
}
}
}

alert(menu);
```
Binary file modified 1-js/04-object-basics/01-object/variable-contains-reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/01-object/variable-contains-reference@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/01-object/variable-copy-reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/01-object/variable-copy-reference@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/01-object/variable-copy-value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/01-object/variable-copy-value@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/02-garbage-collection/family-no-family.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 1-js/04-object-basics/02-garbage-collection/family-no-family@2x.png
Binary file modified 1-js/04-object-basics/02-garbage-collection/family-no-father-2.png
Binary file modified 1-js/04-object-basics/02-garbage-collection/family-no-father.png
Binary file modified 1-js/04-object-basics/02-garbage-collection/family.png
Binary file modified 1-js/04-object-basics/02-garbage-collection/family@2x.png
Binary file modified 1-js/04-object-basics/02-garbage-collection/memory-user-john.png
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


```js run demo
```js run demo solution
let calculator = {
sum() {
return this.a + this.b;
Expand All @@ -20,4 +19,3 @@ calculator.read();
alert( calculator.sum() );
alert( calculator.mul() );
```

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The solution is to return the object itself from every call.

```js run
```js run demo
let ladder = {
step: 0,
up() {
Expand Down Expand Up @@ -28,7 +28,7 @@ ladder.up().up().down().up().down().showStep(); // 1

We also can write a single call per line. For long chains it's more readable:

```js
```js
ladder
.up()
.up()
Expand All @@ -37,4 +37,3 @@ ladder
.down()
.showStep(); // 1
```

2 changes: 1 addition & 1 deletion 1-js/04-object-basics/04-object-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ sayHi(); // undefined

In this case `this` is `undefined` in strict mode. If we try to access `this.name`, there will be an error.

In non-strict mode (if one forgets `use strict`) the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later). This is a historical behavior that `"use strict"` fixes.
In non-strict mode the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later in the chapter [](info:global-object)). This is a historical behavior that `"use strict"` fixes.

Please note that usually a call of a function that uses `this` without an object is not normal, but rather a programming mistake. If a function has `this`, then it is usually meant to be called in the context of an object.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


```js run demo
function Calculator() {

Expand Down
5 changes: 2 additions & 3 deletions 1-js/05-data-types/03-string/3-truncate/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ The maximal length must be `maxlength`, so we need to cut it a little shorter, t

Note that there is actually a single unicode character for an ellipsis. That's not three dots.

```js run
```js run demo
function truncate(str, maxlength) {
return (str.length > maxlength) ?
return (str.length > maxlength) ?
str.slice(0, maxlength - 1) + '…' : str;
}
```

5 changes: 0 additions & 5 deletions 1-js/05-data-types/03-string/4-extract-currency/solution.md
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
```js run
function extractCurrencyValue(str) {
return +str.slice(1);
}
```
4 changes: 2 additions & 2 deletions 1-js/05-data-types/04-array/10-maximal-subarray/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The slow solution
# Slow solution

We can calculate all possible subsums.

Expand Down Expand Up @@ -67,7 +67,7 @@ Let's walk the array and keep the current partial sum of elements in the variabl

If the description is too vague, please see the code, it's short enough:

```js run
```js run demo
function getMaxSubSum(arr) {
let maxSum = 0;
let partialSum = 0;
Expand Down
Binary file modified 1-js/05-data-types/04-array/array-pop.png
Binary file modified 1-js/05-data-types/04-array/array-pop@2x.png
Binary file modified 1-js/05-data-types/04-array/array-shift.png
Binary file modified 1-js/05-data-types/04-array/array-shift@2x.png
Binary file modified 1-js/05-data-types/04-array/array-speed.png
Binary file modified 1-js/05-data-types/04-array/array-speed@2x.png
2 changes: 1 addition & 1 deletion 1-js/05-data-types/04-array/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is one of mo

Arrays support both operations.

In practice we meet it very often. For example, a queue of messages that need to be shown on-screen.
In practice we need it very often. For example, a queue of messages that need to be shown on-screen.

There's another use case for arrays -- the data structure named [stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)).

Expand Down
Binary file modified 1-js/05-data-types/04-array/queue.png
Binary file modified 1-js/05-data-types/04-array/queue@2x.png
Binary file modified 1-js/05-data-types/04-array/stack.png
Binary file modified 1-js/05-data-types/04-array/stack@2x.png
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function camelize(str) {
return str
.split('-') // my-long-word -> ['my', 'long', 'word']
.map(
.split('-') // splits 'my-long-word' into array ['my', 'long', 'word']
.map(
// capitalizes first letters of all array items except the first one
// converts ['my', 'long', 'word'] into ['my', 'Long', 'Word']
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)
) // ['my', 'long', 'word'] -> ['my', 'Long', 'Word']
.join(''); // ['my', 'Long', 'Word'] -> myLongWord
)
.join(''); // joins ['my', 'Long', 'Word'] into 'myLongWord'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Let's walk the array items:
- For each item we'll check if the resulting array already has that item.
- If it is so, then ignore, otherwise add to results.

```js run
```js run demo
function unique(arr) {
let result = [];

Expand Down
14 changes: 14 additions & 0 deletions 1-js/05-data-types/05-array-methods/2-filter-range/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```js run demo
function filterRange(arr, a, b) {
// added brackets around the expression for better readability
return arr.filter(item => (a <= item && item <= b));
}

let arr = [5, 3, 8, 1];

let filtered = filterRange(arr, 1, 4);

alert( filtered ); // 3,1 (matching values)

alert( arr ); // 5,3,8,1 (not modified)
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


function filterRangeInPlace(arr, a, b) {

for (let i = 0; i < arr.length; i++) {
Expand All @@ -12,4 +11,4 @@ function filterRangeInPlace(arr, a, b) {
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```js run demo
function filterRangeInPlace(arr, a, b) {

for (let i = 0; i < arr.length; i++) {
let val = arr[i];

// remove if outside of the interval
if (val < a || val > b) {
arr.splice(i, 1);
i--;
}
}

}

let arr = [5, 3, 8, 1];

filterRangeInPlace(arr, 1, 4); // removed the numbers except from 1 to 4

alert( arr ); // [3, 1]
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```js run no-beautify
function sortByName(arr) {
arr.sort((a, b) => b.name > a.name ? 1 : -1);
arr.sort((a, b) => a.age > b.age ? 1 : -1);
}

let john = { name: "John", age: 25 };
Expand All @@ -12,6 +12,6 @@ let arr = [ john, pete, mary ];
sortByName(arr);

// now sorted is: [john, mary, pete]
alert(arr[1].name); // Mary
alert(arr[0].name); // John
alert(arr[2].name); // Pete
```

6 changes: 3 additions & 3 deletions 1-js/05-data-types/05-array-methods/8-sort-objects/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ importance: 5

# Sort objects

Write the function `sortByName(users)` that gets an array of objects with property `name` and sorts it.
Write the function `sortByName(users)` that gets an array of objects with the `age` property and sorts them by `age`.

For instance:

Expand All @@ -18,6 +18,6 @@ let arr = [ john, pete, mary ];
sortByName(arr);

// now: [john, mary, pete]
alert(arr[1].name); // Mary
alert(arr[0].name); // Mary
alert(arr[2].name); // Pete
```

10 changes: 6 additions & 4 deletions 1-js/05-data-types/05-array-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ Here the [arr.find](mdn:js/Array/find) method comes in handy.
The syntax is:
```js
let result = arr.find(function(item, index, array) {
// should return true if the item is what we are looking for
// if true is returned, item is returned and iteration is stopped
// for falsy scenario returns undefined
});
```

Expand Down Expand Up @@ -313,11 +314,12 @@ The `find` method looks for a single (first) element that makes the function ret

If there may be many, we can use [arr.filter(fn)](mdn:js/Array/filter).

The syntax is roughly the same as `find`, but it returns an array of matching elements:
The syntax is similar to `find`, but filter continues to iterate for all array elements even if `true` is already returned:

```js
let results = arr.filter(function(item, index, array) {
// should return true if the item passes the filter
// if true item is pushed to results and iteration continues
// returns empty array for complete falsy scenario
});
```

Expand Down Expand Up @@ -568,7 +570,7 @@ The calculation flow:

![](reduce.png)

Or in the form of a table, where each row represents is a function call on the next array element:
Or in the form of a table, where each row represents a function call on the next array element:

| |`sum`|`current`|`result`|
|---|-----|---------|---------|
Expand Down
Binary file modified 1-js/05-data-types/05-array-methods/reduce.png
Binary file modified 1-js/05-data-types/05-array-methods/reduce@2x.png
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Here we could also use a plain object instead of the `Map`, because keys are str

That's how the solution can look:

```js run
```js run demo
function aclean(arr) {
let obj = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ map.set("name", "John");
let keys = map.keys();

*!*
// Error: numbers.push is not a function
// Error: keys.push is not a function
keys.push("more");
*/!*
```
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/07-map-set-weakmap-weakset/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Compare it with the regular `Map` example above. Now if `john` only exists as th

- `weakMap.get(key)`
- `weakMap.set(key, value)`
- `weakMap.delete(key, value)`
- `weakMap.delete(key)`
- `weakMap.has(key)`

Why such a limitation? That's for technical reasons. If an object has lost all other references (like `john` in the code above), then it is to be garbage-collected automatically. But technically it's not exactly specified *when the cleanup happens*.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
```js run demo
function sumSalaries(salaries) {

let sum = 0;
for (let salary of Object.values(salaries)) {
sum += salary;
}

return sum; // 650
}

let salaries = {
"John": 100,
"Pete": 300,
"Mary": 250
};

alert( sumSalaries(salaries) ); // 650
```
Or, optionally, we could also get the sum using `Object.values` and `reduce`:

```js
// reduce loops over array of salaries,
// adding them up
// and returns the result
function sumSalaries(salaries) {
return Object.values(salaries).reduce((a, b) => a + b, 0) // 650
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function topSalary(salaries) {
let max = 0;
let maxName = null;

for(let [name, salary] of Object.entries(salaries)) {
for(const [name, salary] of Object.entries(salaries)) {
if (max < salary) {
max = salary;
maxName = name;
Expand Down
Loading