From 534a438ce5e075dad353e7e6704665d6c5a51dc0 Mon Sep 17 00:00:00 2001 From: Tyler Hevia Date: Mon, 16 Oct 2017 11:58:13 -0600 Subject: [PATCH 1/5] :art: Refactor getPersonList - Refactor API call function -- instead of instantiating a new Promise, just return fetch call, which will return a promise by default - Change error handling from if statement to catch method --- index.html | 59 +++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/index.html b/index.html index 508ebb3d..a6be1e54 100644 --- a/index.html +++ b/index.html @@ -46,44 +46,45 @@ --> - - Single Page Application - - - - -
+ + + + +
- - - + + + - - + - - - + \ No newline at end of file From e1889b7045213b128b27e8b312b71edd5e7d4a1b Mon Sep 17 00:00:00 2001 From: Tyler Hevia Date: Mon, 16 Oct 2017 12:07:46 -0600 Subject: [PATCH 2/5] :art: Remove arrow function -Change getFirstName from arrow function to traditional function for the sake of consistency. There is no significant performance benefit to be gained from using arrow functions (to my knowledge), and since getFirstname and getLastName are performing similar tasks, I want to structure them consistently to avoid confusion --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a6be1e54..641145ca 100644 --- a/index.html +++ b/index.html @@ -123,7 +123,7 @@ return person.lastName; } - const getFirstName = (person) => { + function getFirstName(person) { return person.firstName; }; From 7fbaf81111b428e4852cb382a60d47d468c825dc Mon Sep 17 00:00:00 2001 From: Tyler Hevia Date: Mon, 16 Oct 2017 12:39:15 -0600 Subject: [PATCH 3/5] Change shuffleList function - Replace slice with Array.from - List.slice(1) wasn't making a copy of the whole list, because it was starting at the second value in the array. Array.from makes a complete copy --- index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 641145ca..c7962d79 100644 --- a/index.html +++ b/index.html @@ -127,9 +127,10 @@ return person.firstName; }; + // headshot URLs are scheme relative // // prepend http: to prevent invalid schemes like file:// or uri:// - const getImageUrl = (person) => { + function getImageUrl(person) { return `http:${person.headshot.url}`; }; @@ -138,7 +139,6 @@ */ function shuffleList(list) { // Make a copy & don't mutate the passed in list - let result = list.slice(1); let tmp, j, i = list.length - 1 @@ -149,7 +149,7 @@ list[j] = tmp; } - return result; + return list; } From 7208f351deac7f5438ec57e37c655065b1db8e9f Mon Sep 17 00:00:00 2001 From: Tyler Hevia Date: Mon, 16 Oct 2017 12:54:04 -0600 Subject: [PATCH 4/5] Change shuffleList again - Use ES6 syntax to shuffle values --- index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index c7962d79..af5fea69 100644 --- a/index.html +++ b/index.html @@ -139,17 +139,17 @@ */ function shuffleList(list) { // Make a copy & don't mutate the passed in list - + let result = Array.from(list); let tmp, j, i = list.length - 1 for (; i > 0; i -= 1) { j = Math.floor(Math.random() * (i + 1)); - tmp = list[i]; - list[i] = list[j]; - list[j] = tmp; + [tmp, list[i]] = [list[i], tmp]; + [list[i], list[j]] = [list[j], list[i]]; + [list[j], tmp] = [tmp, list[j]] } - return list; + return result; } From 64203935190b1ffaf19959cdc14e46741aa05d38 Mon Sep 17 00:00:00 2001 From: Tyler Hevia Date: Mon, 16 Oct 2017 13:09:52 -0600 Subject: [PATCH 5/5] :tada: fix sortByLastName function - sortByLast name was being called with firstName as the argument of sortObjListByProp. Change firstName to lastName and remove the reverse() method --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index af5fea69..71d8f75c 100644 --- a/index.html +++ b/index.html @@ -203,7 +203,7 @@ const sortByFirstName = sortObjListByProp('firstName'); - const sortByLastName = (personList) => sortByFirstName(personList).reverse(); + const sortByLastName = sortObjListByProp('lastName'); /*==================================================