diff --git a/index.html b/index.html
index 508ebb3d..49314eaf 100644
--- a/index.html
+++ b/index.html
@@ -101,22 +101,14 @@
* ...
* ]
*/
+
function getPersonList() {
- return new Promise((resolve, reject) => {
- fetch('https://willowtreeapps.com/api/v1.0/profiles')
- .then(response => {
- if (response.status !== 200) {
- reject(new Error("Error!"));
- }
-
- response.json().then(imageList => {
- resolve(imageList);
- });
- });
- });
+ return fetch('https://willowtreeapps.com/api/v1.0/profiles')
+ .then(response => response.json())
+ .then(imageList => { return imageList })
+ .catch(error => { return error })
}
-
/*==================================================
DATA TRANSFORMS
@@ -128,13 +120,13 @@
return person.lastName;
}
- const getFirstName = (person) => {
+ function getFirstName(person) {
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}`;
};
@@ -143,15 +135,16 @@
*/
function shuffleList(list) {
// Make a copy & don't mutate the passed in list
- let result = list.slice(1);
+ let tmp, j, i;
+ let result = list.slice(0);
+ let len = list.length;
- let tmp, j, i = list.length - 1
- for (; i > 0; i -= 1) {
+ for (i = 0; i < len; i++) {
j = Math.floor(Math.random() * (i + 1));
- tmp = list[i];
- list[i] = list[j];
- list[j] = tmp;
+ tmp = result[i];
+ result[i] = result[j];
+ result[j] = tmp;
}
return result;
@@ -163,7 +156,7 @@
* searching for.
*/
function filterByName(searchForName, personList) {
- return personList.filter((person) => {
+ return personList.filter(function(person) {
return person.firstName === searchForName || person.lastName === searchForName;
});
}
@@ -188,28 +181,25 @@
function sortObjListByProp(prop) {
return function(objList) {
// Make a copy & don't mutate the passed in list
- let result = objList.slice(1);
+ let result = objList.slice(0);
- result.sort((a, b) => {
- if (a[prop] < b[prop]) {
- return -1;
- }
-
- if (a[prop] > b[prop]) {
- return 1;
- }
-
- return 1;
+ result.sort(function(a, b) {
+ if (a[prop] < b[prop]) return -1;
+ if (a[prop] > b[prop]) return 1;
+ return 0;
});
return result;
};
}
- const sortByFirstName = sortObjListByProp('firstName');
+ const sortByFirstName = sortObjListByProp('firstName');
- const sortByLastName = (personList) => sortByFirstName(personList).reverse();
+ const sortByLastName = sortObjListByProp('lastName');
+ const sortDescendingByLastName = function(personList) {
+ return sortByLastName(personList).reverse();
+ };
/*==================================================
@@ -217,6 +207,7 @@
***************************************************/
+
const Search = (props) => React.DOM.input({
type: 'input',
onChange: props.onChange