Skip to content

Instantly share code, notes, and snippets.

View ZakriaJanjua's full-sized avatar
🦾
Producing

Zakria Janjua ZakriaJanjua

🦾
Producing
View GitHub Profile
@ZakriaJanjua
ZakriaJanjua / inifiniteClosures.js
Created August 13, 2023 18:38
A javascript function that can take infinite closures
function multiply(params) {
return function(args) {
if (args) {
return multiply(params*args)
} else {
return params
}
}
}
@ZakriaJanjua
ZakriaJanjua / CustomFlat.js
Created July 23, 2023 17:23
Custom flat function for arrays in javascript/node.js
Array.prototype.customFlat = function(depth = 1) {
let result = []
for (let arr of this) {
if (Array.isArray(arr) && depth > 0) {
result.push(...arr.customFlat(depth-1))
} else {
result.push(arr)
}
}
return result
@ZakriaJanjua
ZakriaJanjua / countingSort.py
Last active March 30, 2024 23:27
Counting Sort algorithm in Python
# defines the range of the numbers that will be input in the array
RANGE = 100
def countingSort(arr):
# Write your code here
count = [0] * RANGE
result = []
for i in arr:
count[i] += 1
@ZakriaJanjua
ZakriaJanjua / parseInt().js
Created August 10, 2022 19:50
codewars kata of parseInt.js 4kyu solution
function parseInt(string) {
// TODO: it's your task now
const dictionary = {"zero":0,"one":1,"two":2,"three":3,"four":4,"five":5,"six":6,"seven":7,"eight":8,"nine":9,"ten":10,"eleven":11,"twelve":12,"thirteen":13,"fourteen":14,"fifteen":15,"sixteen":16,"seventeen":17,"eighteen":18,"nineteen":19,
"twenty":20, "thirty":30, "forty":40, "fifty":50, "sixty":60, "seventy":70, "eighty":80, "ninety":90};
const multi = {
'hundred': 100,
'thousand': 1000,
'million': 1000000
}
const words = string.split(/ |-/)
@ZakriaJanjua
ZakriaJanjua / shoppingCart.py
Created August 8, 2022 17:04
Hackerrank Python(Basic) certification question. Needed to create a shopping cart
class Item:
def __init__(self, name, price):
self.name = name
self.price = price
item = Item('Bike', 1000)
class ShoppingCart:
# Implement the ShoppingCart here
@ZakriaJanjua
ZakriaJanjua / transformSentence.py
Created August 8, 2022 17:02
Hackerrank Python(Basic) certification test question. Required to manipulate a sentence according to an algorithm.
def transformSentence(sentence):
# Write your code here
words = sentence.split(' ')
result_arr = []
for word in words:
if len(word) == 1:
result_arr.append(word)
continue
new_word = ''
for i in range(0, len(word)):
@ZakriaJanjua
ZakriaJanjua / FindEquivalent.py
Created June 17, 2022 20:50
Input an integer in the function and it will give you the equivalent alphabet of it. The alphabets starts appending after 26
# 26 Z
# 27 AA
# 80 CB
# 702 ZZ
# 728 AAZ
# 705 AAC
# 13456 SWN
# 456977 YYZA
import math
@ZakriaJanjua
ZakriaJanjua / AlgorithmicString.py
Created May 22, 2022 18:49
Given a string as input. When `M` is hit program would copy the preceding character at the end of the string and then remove itself and when `N` is hit program will remove the next character of the string and remove itself too
def MandN(string):
result = ""
string_iter = iter(string)
for i in string_iter:
if (i == "M"):
if (len(result) != 0):
result += result[-1]
elif (i == "N"):
try:
next(string_iter)
@ZakriaJanjua
ZakriaJanjua / CountCharacters.py
Created May 22, 2022 18:23
Take a string as input and count the numbers of characters in their occurrence and return the result with their number of occurrences and the letter.
def countCharacters(string):
single = []
whole = []
result = ""
for i in string:
if (len(single) == 0):
single.append(i)
elif (i == single[0]):
single.append(i)
else:
@ZakriaJanjua
ZakriaJanjua / StringChallenge.js
Created May 21, 2022 18:16
Take a string and invert the case of each character. If the English characters in the string are wrapped between numbers then switch the numbers and if there is any other character then do not switch them.
function StringChallenge(str) {
// code goes here
let result = ""
str = reversing(str)
for (let i = 0; i < str.length; i++) {
let current = str[i].charCodeAt(0)
if (current >= 65 && current <= 90) {
result = result + str[i].toLowerCase()
} else if (current >= 97 && current <= 122) {