# Homework

## JavaScript Iterators

### `.forEach() or .filter()`

Write a function named onlyEven that returns evens numbers in an array.

```
onlyEven([1,2,3,4,5,6,7]) // => [2,4,6]
```

### `.forEach() or .filter()`

* `countIntegers` – counts how many integers there are in an array

```
countIntegers([4, 2.2, 5, 6, 4.2, 8.2, 4]) // => 4
```

* Hint: Google how you can check if a number is an integer in JavaScript

### `.map()` oldie but goodie

Write a function `lengths` that accepts a single parameter as an argument, namely an array of strings. The function should return an array of numbers where each number is the length of the corresponding string. use `.map`

```
lengths(['my', 'cake', 'pudding']); // => [2,4,7]
```

### `.map()`

Write code using `.map()` to have the following input and output:

* `getSquares` – takes in an array of numbers and returns an array of their squares

```
getSquares([1, 2, 3, 4, 5]) // => [1, 4, 9, 16, 25]
```

### `.map(), .filter() & .reduce()`

1. Write an expression using array iterator methods (like filter and reduce) to compute the total value of the machines in the inventory array.

```
var inventory = [
  {type:   "machine", value: 5000},
  {type:   "machine", value:  650},
  {type:      "duck", value:   10},
  {type: "furniture", value: 1200},
  {type:   "machine", value:   77}
]
```

2. Get an array of all the machines with value over 500


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ga0-2.gitbook.io/seifxr10anz-content/week-13/day-2-callbacks-and-asynchronous-code/homework.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
