Skip to content

Instantly share code, notes, and snippets.

View prav-raghu's full-sized avatar
🐍
Working from home

Prav prav-raghu

🐍
Working from home
View GitHub Profile
@prav-raghu
prav-raghu / iterativeBinarySearch.js
Created March 31, 2022 12:07
iterativeBinarySearch
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
@prav-raghu
prav-raghu / recursiveBinarySearch.js
Created March 31, 2022 11:48
Recursive Binary Search in JavaScript
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;
}
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))
def square(n):
total = 0
for k in range(1, n):
if(k % 2 != 0):
total +=(k*k)
return total
print(square(5))
def square(n):
squares = [k*k for k in range(1, n)]
return squares
print(square(100))
def square(data):
squares = []
for k in list(range(1,data)):
squares.append(k*k)
return squares
print(square(5))
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))
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)))
def is_multiple(n,m):
if (n % m == 0):
return True
else:
return False
print(is_multiple(10,3))
["Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
"Austria",