Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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
- // **********************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement