7-Tips for Starting a React Project!

Input the following code inside your terminal:

npx create-react-app my-app

Congratulations you are done! the whole project has started! (It was a joke, but that has typically been the first command I enter to start a react project.) But let’s get serious. React is a wide JavaScript library, used by…

Python-algos: Sentence Reversal

Given a string of words, reverse all the words. For example:

“Hi my name is Avi”, becomes “Avi is name my Hi”.

def rev_word3(s):

words = []
length = len(s)
spaces = [' ']
i = 0
while i < length:
if s[i] not in spaces:
word_start = i

while i < length and s[i] not in spaces:
i += 1
words.append(s[word_start:i])
i += 1
return " ".join(reversed(words))

The code above makes an empty array of words, finds the length of the input, an array with a space and an index start point. The code checks for the index being shorter than the length of the input in the first loop. The second loop checks for the final letter index of the word, then it returns the words reversed.

Python-algos: Largest Continuous Sum

Given an array of integers (positive and negative) find the largest continuous sum. An example of an array would be the following: [7,2,-6,3,4,10,10,-10,-10] . The array’s maximum sum would be 30, summing everything until the last two -10’s are not included in the sum.

def large_cont_sum(arr):

if len(arr)==0:
return 0

max_sum = current_sum = arr

for num in arr[1:]:
current_sum = max(current_sum + num, num)
max_sum = max(current_sum, max_sum)
return max_sum

Python-Algos: Find the Missing Element

Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given the two arrays, find which element is missing in the second array.

def findt_missing(arr1,arr2):
arr1.sort()
arr2.sort()

for num1, num2 in zip(arr1,arr2):
if num1 != num2:
return num1
return arry1[-1]

The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc.

If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.

a = ("John", "Charles", "Mike")
b = ("Jenny", "Christy", "Monica")
x = zip(a, b)
print(tuple(x))
Reslult:
(('John', 'Jenny'), ('Charles', 'Christy'), ('Mike', 'Monica'))

The bigO notation for the solution of our problem is nLog(n).

Python-Algos: Array Pair Sum

They’re many ways to approach this problem, but you have to consider the time it takes to run the code once the data becomes much bigger than your sample test data.

The Array Pair Sum problem: Given an integer array, output all the unique pairs that sum up to a specific value C.

def pair_sum(arr, C):
if len(arr)<2:
return
seen = set()
output = set()
for num in arr:
target = C - num
if target not in seen:
else: 