{"id":1208,"date":"2019-07-23T22:44:13","date_gmt":"2019-07-24T05:44:13","guid":{"rendered":"https:\/\/doubleecpu.com\/?page_id=1208"},"modified":"2019-07-24T02:05:56","modified_gmt":"2019-07-24T09:05:56","slug":"myarrays1","status":"publish","type":"page","link":"https:\/\/doubleecpu.com\/index.php\/raspian-linux-programs\/javascript-2\/myjs30\/myarrays1\/","title":{"rendered":"myArrays1"},"content":{"rendered":"\n<div>\n  <p>Inventors from 1500-1600<\/p>\n  <p id=\"array-inventors\"><\/p>\n<\/div>\n<div>\n  <p>Inventors Full Name List<\/p>\n  <p id=\"arrayfullnames\"><\/p> \n<\/div>  \n<div>\n  <p>Click on button to sort by birthday<\/p>\n  <button onclick=\"BtnSortBirthday()\">Birthday Sort<\/button>\n<script>\n    \/\/ Some data to work with\n    const inventors = [\n      { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },\n      { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },\n      { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },\n      { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },\n      { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },\n      { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },\n      { first: 'Max', last: 'Planck', year: 1858, passed: 1947 },\n      { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 },\n      { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 },\n      { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 },\n      { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 },\n      { first: 'Hanna', last: 'Hammarstr\u00f6m', year: 1829, passed: 1909 }\n    ];\n\n    const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black, Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William'];\n\n  \/\/ Array.prototype.filter()\n  \/\/ 1. Filter the list of inventors for those who were born in the 1500's\n  var fifteen;\n  fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600))\ntext = \"<ul>\";\nfifteen.forEach(generate_names);\ntext += \"<\/ul>\";\ndocument.getElementById(\"array-inventors\").innerHTML = text;\n\nfunction generate_names(value) {\n  text += \"<li>\" + value[\"first\"] + \" \" + value[\"last\"] + \" \" + value[\"year\"] + \"<\/li>\";\n} \n  \/\/ Array.prototype.map()\n  \/\/ 2. Give us an array of the inventors' first and last names\n  var fullNames = [];\n  fullNames = inventors;\n  console.log(fullNames);\n  text = \"<ul>\";\n  fullNames.forEach(generate_names);\n  text += \"<\/ul>\";\n  console.log(text);\n  document.getElementById(\"arrayfullnames\").innerHTML = text;\n\n  \/\/ Array.prototype.sort()\n  \/\/ 3. Sort the inventors by birthdate, oldest to youngest  \n  var birthdaysorted = [];\n  function BtnSortBirthday() {\n    birthdaysorted = inventors.sort(function(a, b){return a.year - b.year});\n    console.log(birthdaysorted);\n    displaybirthdaysort();\n  }\n\n  function displaybirthdaysort(){\n  text = \"<ul>\";\n  birthdaysorted.forEach(generate_names);\n  text += \"<\/ul>\";\n  console.log(text);\n  document.getElementById(\"arrayfullnames\").innerHTML = text;   \n  }\n  \/\/ Array.prototype.reduce()\n    \/\/ 4. How many years did all the inventors live?\n\n    \/\/ 5. Sort the inventors by years lived\n\n    \/\/ 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name\n    \/\/ https:\/\/en.wikipedia.org\/wiki\/Category:Boulevards_in_Paris\n\n\n    \/\/ 7. sort Exercise\n    \/\/ Sort the people alphabetically by last name\n\n    \/\/ 8. Reduce Exercise\n    \/\/ Sum up the instances of each of these\n    const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];\n\n  <\/script>\n","protected":false},"excerpt":{"rendered":"<p>Inventors from 1500-1600 Inventors Full Name List Click on button to sort by birthday Birthday Sort<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1022,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1208","page","type-page","status-publish","hentry"],"featured_media_urls":[],"_links":{"self":[{"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/pages\/1208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/comments?post=1208"}],"version-history":[{"count":0,"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/pages\/1208\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/pages\/1022"}],"wp:attachment":[{"href":"https:\/\/doubleecpu.com\/index.php\/wp-json\/wp\/v2\/media?parent=1208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}