This file contains 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
var array = [1,2,3,4,5] | |
let iterativeFunction = function (arr, x) { | |
let start=0, end=arr.length-1; | |
// Iterate while start not meets end | |
while (start<=end){ | |
// Find the mid index |
This file contains 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
var array = [1,2,3,4,5] | |
let recursiveFunction = function(array,x,start,end){ | |
if(start > end){ | |
return false | |
} | |
let mid = Math.floor((start + end)/2) | |
if(array[mid] === x){ | |
return true; | |
} |
This file contains 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
def square(n): | |
squares = sum(k*k for k in range(1, n) if k % 2 != 0 and k > 0) | |
return squares | |
print(square(5)) |
This file contains 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
def square(n): | |
total = 0 | |
for k in range(1, n): | |
if(k % 2 != 0): | |
total +=(k*k) | |
return total | |
print(square(5)) |
This file contains 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
def square(n): | |
squares = [k*k for k in range(1, n)] | |
return squares | |
print(square(100)) |
This file contains 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
def square(data): | |
squares = [] | |
for k in list(range(1,data)): | |
squares.append(k*k) | |
return squares | |
print(square(5)) |
This file contains 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
def minmax(data): | |
max = data[0] | |
min = data[0] | |
for k in data: | |
if(k > max): | |
max = k | |
if(k < min): | |
min = k | |
print('max: ' + str(max)) | |
print('min: ' + str(min)) |
This file contains 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
def is_even(k): | |
if(k ^ 1 == k+1): | |
return True | |
else: | |
return False | |
k = input("Please provide a number: ") | |
print(is_even(int(k))) |
This file contains 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
def is_multiple(n,m): | |
if (n % m == 0): | |
return True | |
else: | |
return False | |
print(is_multiple(10,3)) |
This file contains 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
["Afghanistan", | |
"Albania", | |
"Algeria", | |
"Andorra", | |
"Angola", | |
"Antigua and Barbuda", | |
"Argentina", | |
"Armenia", | |
"Australia", | |
"Austria", |
NewerOlder