Last active
August 12, 2019 07:46
-
-
Save YannMjl/95c862ca9d4e677cfa9b65f61e32091d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // return true if an item exists in list | |
| // and false if it doesn't | |
| var fruits = ["Banana", "Orange", "Apple", "Mango"]; | |
| var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]; | |
| function checkItemInList(item, list) { | |
| return list.includes(item); | |
| } | |
| console.log('Is Mango in Fruit List:', checkItemInList('Mango', fruits)); // true | |
| console.log('Is Avocado in Fruit List:', checkItemInList('Avocado', fruits)); // false | |
| console.log('Is 14 in numbers list:', checkItemInList(14, numbers)); // true | |
| console.log('Is 15 in numbers list:', checkItemInList(15, numbers)); // false | |
| // ********************************************************************************** | |
| // - In the case the run time of checkItemInList is O(n) | |
| // - n being the number of item in the array list | |
| // - Big O Notaion favor the worse case scenaior: the item we are looking for | |
| // - is the last item in the list array | |
| // ********************************************************************************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment