Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save escottalexander/8bb27156924c5aa37e141f9d2b7cc1f7 to your computer and use it in GitHub Desktop.
Save escottalexander/8bb27156924c5aa37e141f9d2b7cc1f7 to your computer and use it in GitHub Desktop.
https://repl.it/@ElliottAlexande/Make-student-reports-drill
https://repl.it/@ElliottAlexande/Enroll-in-summer-school-drill
https://repl.it/@ElliottAlexande/find-by-id-drill
https://repl.it/@ElliottAlexande/validate-object-keys-drill
@Jefftopia
Copy link

https://repl.it/@ElliottAlexande/Make-student-reports-drill

There's an even easier way using map! Array.prototype.map() allows you to iterate over an array that has some structure, and return a new array in a different structure. The structure depends on the logic in your callback, which you've already done!

function makeStudentsReport(data) {
    // use map to iterate over array enties and return a new array of strings
    // use a fat-arrow function (=>) to save a few bytes and not have to write the word "function"
    return data.map((key) => {
        // use a template-literate to create the string we want to return
        // For an entry to be in the returned array, be sure to _return_ the string here
        / without the return, the result array will have an undefined value
        return `${key.name}: ${key.grade}`;
    });
}

https://repl.it/@ElliottAlexande/find-by-id-drill
Your solution here works great, but it too can be a little simpler!

function find(items, id) {
        // in lieu of `findIndex`, just use `find` :)
	return items.find(val => id === val.id);
}

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment