[Fix] Corrected bug found in Shopping List challenge (#35017)

* fix: corrected bug found in issue #16044

* fix: account for empty strings

Co-Authored-By: RandellDawson <5313213+RandellDawson@users.noreply.github.com>

* fix: corrected wrong logic
pull/35307/head
Randell Dawson 2019-02-23 23:58:55 -08:00 committed by Aditya
parent 5b73ed54e2
commit b83ab53047
1 changed files with 4 additions and 4 deletions

View File

@ -64,14 +64,14 @@ var hasNumber = false;
if(myList.length > 0) { if(myList.length > 0) {
hasString = true; hasString = true;
hasNumber = true; hasNumber = true;
myList.forEach(function(elem) { for (var elem of myList) {
if(typeof elem[0] !== 'string') { if(!elem || !elem[0] || typeof elem[0] !== 'string') {
hasString = false; hasString = false;
} }
if(typeof elem[1] !== 'number') { if(!elem || typeof elem[1] !== 'number') {
hasNumber = false; hasNumber = false;
} }
}); }
} }
count = myList.length; count = myList.length;
return JSON.stringify(myList); return JSON.stringify(myList);