Files
exercises/w6_1_FP/index.js
Andrea Bianchi 9054d5c511 6.1
2026-04-06 09:26:07 +09:00

52 lines
1.4 KiB
JavaScript

const people = [
{ name: 'Bob', last: 'Johnson', age: 30 },
{ name: 'Charlie', last: 'Brown', age: 25 },
{ name: 'David', last: 'Williams', age: 35 },
{ name: 'Alice', last: 'Smith', age: 28 },
{ name: 'Eve', last: 'Davis', age: 22 },
{ name: 'Frank', last: 'Miller', age: 40 },
];
const buttonName = document.getElementById('sort-by-name');
const buttonLast = document.getElementById('sort-by-last');
const buttonAge = document.getElementById('sort-by-age');
// Helpers
const pipe =
(...functions) =>
(value) => {
return functions.reduce((acc, fn) => fn(acc), value);
};
const render = (listItems) => {
const ul = document.getElementById('people-list');
ul.innerHTML = listItems.join('');
};
// Exercise helpers
const compareByName = (a, b) => a.name.localeCompare(b.name);
const compareByLast = (a, b) => a.last.localeCompare(b.last);
const compareByAge = (a, b) => a.age - b.age;
const sortPeopleBy = /* ... PLACEHOLDER ... */ () => {};
const peopleToString = (people) => {
return 'PLACEHOLDER';
};
const peopleToListItems = (strings) => 'PLACEHOLDER';
// Main
const byname = /* ... PLACEHOLDER ... */ undefined;
const bylast = /* ... PLACEHOLDER ... */ undefined;
const byage = /* ... PLACEHOLDER ... */ undefined;
byname(people);
buttonName.addEventListener('click', () => undefined);
buttonLast.addEventListener('click', () => undefined);
buttonAge.addEventListener('click', () => undefined);