Skip to content

Commit

Permalink
fix parte final capítulo 3 - versão inglês
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdouglas committed Nov 26, 2014
1 parent 38f54e3 commit 3098b57
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions chapters/03-funcoes.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,14 @@ Separando as tarefas diferentes seu programa executa diferentes funções e isso

The previous chapter introduced the standard function Math.min that returns its smallest argument. We can do that ourselves now. Write a function min that takes two arguments and returns their minimum.

// Your code here.
```js
// Your code here.

console.log(min(0, 10));
// → 0
console.log(min(0, -10));
// → -10
console.log(min(0, 10));
// → 0
console.log(min(0, -10));
// → -10
```

T> If you have trouble putting braces and parentheses in the right place to get a valid function definition, start by copying one of the examples in this chapter and modifying it.
T>
Expand All @@ -578,14 +580,16 @@ Define a recursive function isEven corresponding to this description. The functi

Test it on 50 and 75. See how it behaves on -1. Why? Can you think of a way to fix this?

// Your code here.

console.log(isEven(50));
// → true
console.log(isEven(75));
// → false
console.log(isEven(-1));
// → ??
```js
// Your code here.

console.log(isEven(50));
// → true
console.log(isEven(75));
// → false
console.log(isEven(-1));
// → ??
```

T> Your function will likely look somewhat similar to the inner `find` function in the recursive `findSolution` example in this chapter, with an `if/else if/else` chain that tests which of the three cases applies. The final else, corresponding to the third case, makes the recursive call. Each of the branches should contain a return statement or in some other way arrange for a specific value to be returned.
T>
Expand All @@ -599,12 +603,14 @@ Write a function countBs that takes a string as its only argument and returns a

Next, write a function called `countChar` that behaves like `countBs`, except it takes a second argument that indicates the character that is to be counted (rather than counting only uppercase "B" characters). Rewrite `countBs` to make use of this new function.

// Your code here.
```js
// Your code here.

console.log(countBs("BBC"));
// → 2
console.log(countChar("kakkerlak", "k"));
// → 4
console.log(countBs("BBC"));
// → 2
console.log(countChar("kakkerlak", "k"));
// → 4
```

T> A loop in your function will have to look at every character in the string by running an index from zero to one below its length (< string.length). If the character at the current position is the same as the one the function is looking for, it adds 1 to a counter variable. Once the loop has finished, the counter can be returned.
T>
Expand Down

1 comment on commit 3098b57

@joaostein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.