Merge pull request #1759 from cycduck/wage-gap-fix

Gender pay gap noticed in recursion article.md
This commit is contained in:
Ilya Kantor 2020-02-18 23:50:27 +00:00 committed by GitHub
commit 2437d3de2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -302,7 +302,7 @@ let company = {
salary: 1000 salary: 1000
}, { }, {
name: 'Alice', name: 'Alice',
salary: 600 salary: 1600
}], }],
development: { development: {
@ -350,7 +350,7 @@ The algorithm is probably even easier to read from the code:
```js run ```js run
let company = { // the same object, compressed for brevity let company = { // the same object, compressed for brevity
sales: [{name: 'John', salary: 1000}, {name: 'Alice', salary: 600 }], sales: [{name: 'John', salary: 1000}, {name: 'Alice', salary: 1600 }],
development: { development: {
sites: [{name: 'Peter', salary: 2000}, {name: 'Alex', salary: 1800 }], sites: [{name: 'Peter', salary: 2000}, {name: 'Alex', salary: 1800 }],
internals: [{name: 'Jack', salary: 1300}] internals: [{name: 'Jack', salary: 1300}]
@ -372,7 +372,7 @@ function sumSalaries(department) {
} }
*/!* */!*
alert(sumSalaries(company)); // 6700 alert(sumSalaries(company)); // 7700
``` ```
The code is short and easy to understand (hopefully?). That's the power of recursion. It also works for any level of subdepartment nesting. The code is short and easy to understand (hopefully?). That's the power of recursion. It also works for any level of subdepartment nesting.