Skip to content

Instantly share code, notes, and snippets.

View IUnLife's full-sized avatar

Aayushi Narula Baweja IUnLife

  • Gurgaon, India
View GitHub Profile
// Binary Search(Iterative Approach)
var binarySearch = function (array, number) {
var start = 0;
var end = array.length - 1;
// Iterate while start not meets end
while (start <= end) {
// Find the mid index
@IUnLife
IUnLife / bigO1.js
Created August 12, 2019 07:46 — forked from YannMjl/bigO1.js
// 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;
}
@IUnLife
IUnLife / bigOn.js
Created August 12, 2019 07:46 — forked from YannMjl/bigOn.js
// 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
// read an array of array
function readArrayOfArray() {
// This is an array of arrays.
// It is a little easier to read like this:
var arrayNumberFruit = [
[1, 'Orange'],
[2, 'Banana'],
[3, 'Apple'],
[4, 'Mango']
];
// recursive calculation of Fibonacci numbers
function fibonacci(number) {
if (number <= 1) return number;
return fibonacci(number - 2) + fibonacci(number - 1);
}
console.log(fibonacci(5));
console.log(fibonacci(6));
console.log(fibonacci(7));