Skip to content

Instantly share code, notes, and snippets.

View anushshukla's full-sized avatar
💭
Silently and secretly building awesome applications

Anush Shukla anushshukla

💭
Silently and secretly building awesome applications
View GitHub Profile
@anushshukla
anushshukla / flattenNestedArrAndSort.js
Created July 23, 2019 11:25
Flatten a nested array in sorted order
// Input
// [5, 10, 11, [2, 8], [12, 1, 4], [9, [5,4, 12]], 17]
// Output
// [1, 2, 4, 5, 8,9,10, 11, 12, 17]
function isArray(value) {
return value instanceof Array;
}
function getgetFlatArray2(arr) {
@anushshukla
anushshukla / mergeAndSortArr.js
Created July 23, 2019 11:23
Merge 2 arrays and sort it
// [1, 3, 6, 9,10, 2, 5] and [3,1,9,4,17,18,10]
// [1, 2, 3, 6, 9, 10, 17, 18]
//merge
//return one array sorted []
function getSortedArr(arr) {
var a = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] > arr[i+1]) {
@anushshukla
anushshukla / scopeCheck.js
Created July 23, 2019 09:50
Checking opening and close scope
function isOpeningTag(char) {
return ['{', '[', '('].includes(char)
}
function isClosingTag(char) {
return ['}', ']', ')'].includes(char)
}
function checkScope(str){
var openingTagsCount = 0;
@anushshukla
anushshukla / calculator.js
Created July 11, 2019 06:11
NodeJs Script for a Basic Calculator
const add = function(input1, input2) {
return input1 + input2;
}
const subtract = function(input1, input2) {
return input1 - input2;
}
const multiple = function(input1, input2) {
return input1 * input2;
}
const divide = function(input1, input2) {
@anushshukla
anushshukla / redisCleanup.py
Created July 11, 2019 06:05
Pyhton Script to update the expire time of the first 10 Redis key
import redis
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
i = 0
for key in r.scan_iter("*",3):
# delete the key
print(key)
r.expire(key,21600)
i +=1
if i > 10:
break
@anushshukla
anushshukla / findValueFromAlternateSortedArray.js
Last active July 3, 2019 01:28
Given an array in which elements at odd indices are sorted & elements at even indices are sorted individually. Please write a function to search an element in the array.
const sample = [1, 6, 4, 10, 27, 15, 120, 25, 222, 30];
const sampl2 = [1, 6, 4, 10, 27, 15, 20, 25, 22, 30];
const isEven = integer => integer % 2 === 0;
const findValueFromAlternateSortedArray = (arr, search, prevIndex = 0) => {
const lastIndex = arr.length - 1;
const hasOneValue = arr.length === 1;
const pivotIndex = Math.floor(lastIndex / 2);
const nextPivotIndex = isEven(lastIndex) ? pivotIndex : pivotIndex + 1;
@anushshukla
anushshukla / getArrangedBlackWhiteBalls.js
Created July 1, 2019 10:39
Given a very long array of black and white balls. Assuming you can only swap any two balls at a time, please bring all the white balls to front and black balls to end.
const isWhiteBall = ball => ball === 'W';
const arrangeBlackWhiteBalls = (whiteBalls, blackBalls) => ball => {
if (isWhiteBall(ball)) whiteBalls.push(ball);
else blackBalls.push(ball);
}
const getArrangedBlackWhiteBalls = ballsArr => {
const ballsRearranged = [];
const whiteBalls = [];
@anushshukla
anushshukla / areRangesMatching.js
Last active July 2, 2019 06:24
Matching Ranges for a certain value
const sample = [1, 6, 4, 10, 27, 15, 120, 25, 222, 30];
const sampl2 = [1, 6, 4, 10, 27, 15, 20, 25, 22, 30];
const isEven = integer => integer % 2 === 0;
const findValueFromAlternateSortedArray = (arr, search, prevIndex = 0) => {
const arrLen = arr.length - 1;
const pivotIndex = Math.floor(arrLen / 2);
const nextPivotIndex = isEven(arrLen) ? pivotIndex : pivotIndex + 1;
const pivotIndexValue = arr[pivotIndex];
@anushshukla
anushshukla / altTabApplicationList.js
Created June 30, 2019 08:27
Get Revised Open Application List on pressing of Alt + Tab (no of tab hits, matters)
function moveElement(array, fromIndex, toIndex) {
var element = array[fromIndex];
array.splice(fromIndex, 1);
array.splice(toIndex, 0, element);
}
function getTabList(openApplicationsCount, tabKeyPressedCount, openApplicationsList) {
var activeTabApplicationIndex = tabKeyPressedCount - 1;
// var activeApplicationTab = openApplicationsList[activeTabApplicationIndex];
// openApplicationsList.splice(activeTabApplicationIndex, 1);
@anushshukla
anushshukla / nestedCategoryReactListing.html
Created June 25, 2019 03:27
Nested Category Listing Sample in React
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
ul {
list-style-type: none;
}
</style>
</head>