From b83ab53047c1a8f06d5ffc82c448daa3f3efa751 Mon Sep 17 00:00:00 2001 From: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Date: Sat, 23 Feb 2019 23:58:55 -0800 Subject: [PATCH] [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 --- .../basic-javascript/shopping-list.english.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.english.md index 2769b43bbad..0c24041c70b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.english.md @@ -64,14 +64,14 @@ var hasNumber = false; if(myList.length > 0) { hasString = true; hasNumber = true; - myList.forEach(function(elem) { - if(typeof elem[0] !== 'string') { + for (var elem of myList) { + if(!elem || !elem[0] || typeof elem[0] !== 'string') { hasString = false; } - if(typeof elem[1] !== 'number') { + if(!elem || typeof elem[1] !== 'number') { hasNumber = false; } - }); + } } count = myList.length; return JSON.stringify(myList);