Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Haaste: Valitse Tiettyjä Tietoja Filter()-Metodilla | Edistyneet Taulukkometodit ja Muunnokset
Javascriptin tietorakenteet

bookHaaste: Valitse Tiettyjä Tietoja Filter()-Metodilla

Tehtävä

Saat taulukon opiskelijaolioita. Käytä filter()-metodia luodaksesi uuden taulukon nimeltä highScorers, joka sisältää vain ne opiskelijat, joiden koepisteet ovat suuremmat tai yhtä suuret kuin 90.

  • Alkuperäinen taulukko on nimeltään students, ja se sisältää olioita, joissa on ominaisuudet name ja score.
  • Tarkista, onko opiskelijan pisteet suuremmat tai yhtä suuret kuin 90.
  • Käytä filter()-metodia students-taulukossa luodaksesi uuden taulukon highScorers, joka sisältää vain korkeat pisteet saaneet opiskelijat.
123456789101112131415
const students = [ { name: "Alice", score: 92 }, { name: "Bob", score: 87 }, { name: "Charlie", score: 95 }, { name: "David", score: 78 }, { name: "Emma", score: 90 }, ]; const highScorers = students.___((___) => { return ___; }); for (let i = 0; i < highScorers.length; i += 1) { console.log(highScorers[i].name); }
copy

Odotettu tuloste:

Alice
Charlie
Emma

filter()-metodi luo uuden taulukon sisältäen vain ne alkiot, jotka täyttävät palautetun ehdon callback-funktiossa.

123456789101112131415
const students = [ { name: "Alice", score: 92 }, { name: "Bob", score: 87 }, { name: "Charlie", score: 95 }, { name: "David", score: 78 }, { name: "Emma", score: 90 }, ]; const highScorers = students.filter((student) => { return student.score >= 90; }); for (let i = 0; i < highScorers.length; i += 1) { console.log(highScorers[i].name); }
copy

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 4

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Can you explain how the filter() method works in this example?

What would happen if I changed the score threshold to 85?

Can you show how to display both the name and score of the high scorers?

Awesome!

Completion rate improved to 2.27

bookHaaste: Valitse Tiettyjä Tietoja Filter()-Metodilla

Pyyhkäise näyttääksesi valikon

Tehtävä

Saat taulukon opiskelijaolioita. Käytä filter()-metodia luodaksesi uuden taulukon nimeltä highScorers, joka sisältää vain ne opiskelijat, joiden koepisteet ovat suuremmat tai yhtä suuret kuin 90.

  • Alkuperäinen taulukko on nimeltään students, ja se sisältää olioita, joissa on ominaisuudet name ja score.
  • Tarkista, onko opiskelijan pisteet suuremmat tai yhtä suuret kuin 90.
  • Käytä filter()-metodia students-taulukossa luodaksesi uuden taulukon highScorers, joka sisältää vain korkeat pisteet saaneet opiskelijat.
123456789101112131415
const students = [ { name: "Alice", score: 92 }, { name: "Bob", score: 87 }, { name: "Charlie", score: 95 }, { name: "David", score: 78 }, { name: "Emma", score: 90 }, ]; const highScorers = students.___((___) => { return ___; }); for (let i = 0; i < highScorers.length; i += 1) { console.log(highScorers[i].name); }
copy

Odotettu tuloste:

Alice
Charlie
Emma

filter()-metodi luo uuden taulukon sisältäen vain ne alkiot, jotka täyttävät palautetun ehdon callback-funktiossa.

123456789101112131415
const students = [ { name: "Alice", score: 92 }, { name: "Bob", score: 87 }, { name: "Charlie", score: 95 }, { name: "David", score: 78 }, { name: "Emma", score: 90 }, ]; const highScorers = students.filter((student) => { return student.score >= 90; }); for (let i = 0; i < highScorers.length; i += 1) { console.log(highScorers[i].name); }
copy

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 4
some-alt