[S5] BW JS Warmup Flashcards

1
Q

Schreibe eine Methode, welche einen Array aus Pet Objekten erhält und folgendes wiedergibt.

function(arr, species, multiply_years)

The combined dogs’ ages: 154

A
function sumPetYears(arr, kind, multiply) {
    return `The combined ${kind}s' ages: ${arr.filter(element => element.species === kind).map(element => element.age).reduce((sum, age) => {return sum += age;}, 0) * multiply}`;
  }

console. log(sumPetYears(pets, ‘dog’, 7));
console. log(sumPetYears(pets, ‘cat’, 4));
console. log(sumPetYears(pets, ‘parakeet’, 5));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Console Logge jedes Element eines Arrays das 0 oder durch 3 teilbar ist

A

unimaginativeArray.forEach(element => {if(element % 3 == 0) {console.log(element)}});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Wie schreibt man eine Stack Klasse in JavaScript?

A
class Stack {
    constructor(){
    this.storage = [];
    this.first = this.storage[0];
    }
    add(element){
      return this.storage.push(element);
    }
    remove(element){
      return this.storage.pop(element);
    }
    numOfItems(){
      return this.storage.length == 0 ? "There are no items in your Stack." : this.storage.length;
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Schreibe eine Funktion die alle Vokale eines Strings zählt

A
function vowelCount(str) {
  return str.split("").filter(char => char.toUpperCase() === 'A' || char.toUpperCase() === 'E' || char.toUpperCase() === 'I' || char.toUpperCase() === 'O' || char.toUpperCase() === 'U').length;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Wie wandelt man ein Integer in Binary um?

A
function toBinaryString(number) {
  return number.toString(2);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly