Skip to content

Instantly share code, notes, and snippets.

@YannMjl
Last active August 12, 2019 07:46
Show Gist options
  • Save YannMjl/1bb258ff93d20b52ca2b1378f65872d6 to your computer and use it in GitHub Desktop.
Save YannMjl/1bb258ff93d20b52ca2b1378f65872d6 to your computer and use it in GitHub Desktop.
// get the lenght of an array list
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
function getListLenght(list) {
var _lenght = list.length;
return _lenght;
}
console.log('The number of item in list is: ', getListLenght(fruits)); // 4
console.log('The number of item in list is: ', getListLenght(numbers)); // 14
// **********************************************************************************
// - In this case the run time of getListLenght is costant: O(1)
// - It'll take the same time to run no matter the number of item in the array list
// **********************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment