Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // get the lenght of an array list
  2.  
  3. var fruits = ["Banana", "Orange", "Apple", "Mango"];
  4. var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
  5.  
  6. function getListLenght(list) {
  7. var _lenght = list.length;
  8. return _lenght;
  9. }
  10.  
  11. console.log('The number of item in list is: ', getListLenght(fruits)); // 4
  12. console.log('The number of item in list is: ', getListLenght(numbers)); // 14
  13.  
  14. // **********************************************************************************
  15. // - In this case the run time of getListLenght is costant: O(1)
  16. // - It'll take the same time to run no matter the number of item in the array list
  17. // **********************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement