Skip to content

Instantly share code, notes, and snippets.

@venomnert
Created June 30, 2017 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venomnert/c921cb1d3e8f484cffc23f8185400a9f to your computer and use it in GitHub Desktop.
Save venomnert/c921cb1d3e8f484cffc23f8185400a9f to your computer and use it in GitHub Desktop.
const schools = [
{ name: "St. Marcellinus Secondary School", address: "730 Courtneypark Drive West" },
{ name: "Sir William Mulock S.S.", address: "705 Columbus Way" },
{ name: "George Harvey Collegiate Institute", address: "1700 Keele St" },
{ name: "Dr. G.W. Williams S.S.", address: "39 Dunning Ave." },
{ name: "Weston Collegiate Institute", address: "100 Pine St" }
];
const _pipe = (a, b) => (arg) => b(a(arg));
const pipe = (...ops) => ops.reduce(_pipe);
//1. Iterate over the array of schools
//2. Make a li element containing the school name and address separated by '-'
//3. Append the li to the ul with an id of 'school-list'
const makeLi = (schoolObj) => {
const newLI = document.createElement('li');
newLI.appendChild(document.createTextNode(`${schoolObj.name} - ${schoolObj.address}`));
return newLI
}
const appendLiToSchoolList = (li) => {
let schoolList = document.querySelector('#school-list');
return schoolList.appendChild(li);
}
const generateLi = pipe(makeLi,appendLiToSchoolList);
schools.forEach(school => generateLi(school));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment