---
# System prepended metadata

title: 'exercice 1: FizzBuzz'

---

# exercice 1: FizzBuzz


```javascript

function fizzbuzz(i) {
    if (i%15 ===0){
        console.log(i,"fizzbuzz");
    }
    else if (i % 3 ===0) {
        console.log(i,"fizz");
    }
    else if (i%5 ===0){
        console.log(i,"buzz");
    }
    else{
        console.log(i);
    }
}
function main() {
    for (let i=0;i<100;i++){
        fizzbuzz(i);
    }
}
main();
```


```javascript
const getFizzBuzzLine = function (i) {
    let res = '';
    if (i % 3 === 0) {
        res += 'fizz';
    }
    if (i % 5 === 0) {
        res += 'buzz';
    }
    if (res === '') {
        res += i;
    }
    return res;
}
for (let j = 0; j < 100; ++j) {
    console.log(j, getFizzBuzzLine(j));
}

```

# Exercice 2

Ecrire une fonction
```typescript=
function f(text: string, alphabet: Array<string>): boolean;
```

```javascript=
f('hello', ['h', 'e', 'l', 'z' ,'o', 'p']) === true
f('hello', ['h', 'e', 'l', 'z']) === false
```

```javascript=
function alphabinclud(texte, alphabet){
    for (let i = 0; i < texte.length; i++) { // n fois
        if(!alphabet.includes(texte[i])){ // m fois
            return false;
        }
    }
    return true;
}
```
-> O(n * m) < O(n^2)

```javascript=
function alphabinclud(texte, alphabet){
    const set = new Set(alphabet);
    for (let i = 0; i < texte.length; i++) {
        if(!set.has(texte[i])){
            return false;
        }
    }
    return true;
}
```
-> O( n + m) < O(2 * n) ~ O(n)
