├── .github └── ISSUE_TEMPLATE │ └── feature_request.md ├── .vscode └── launch.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DSA in javaScript ├── BST │ └── bst.js ├── backtracking │ ├── Backtracking in array.js │ └── find subsets.js ├── bit manupaltion │ ├── 1342. Number of Steps to Reduce a Number to Zero.js │ ├── 148. XOR Operation in an Array.js │ ├── 1684. Count the Number of Consistent Strings.js │ ├── 1720. Decode XORed Array.js │ ├── 67. Add Binary.js │ ├── Exceptionally odd.js │ ├── Missing number in array.js │ └── odd or even.js ├── divide and conqure │ ├── dac.js │ ├── merge sort.js │ ├── min and max.js │ └── power of n.js ├── dp │ └── fibonacci series.js ├── greedy algorithm │ ├── Fractional Knapsack - GFG │ │ ├── README.md │ │ └── fractional-knapsack.js │ └── knapsack problem.js ├── linked list │ ├── Linkedlist Basic.js │ ├── practice.js │ └── traversing Linked list.js └── sorting │ ├── merge sort.js │ └── quick sort.js ├── JsChallanger └── JavaScript Basic │ ├── Basic JavaScript math operators │ └── script.js │ ├── Check if a number is even │ └── script.js │ ├── Check if a number is whole number │ └── script.js │ ├── Check whether a string contains another string and concatenate │ └── script.js │ ├── Comparison operators, strict equality │ ├── index.html │ └── script.js │ ├── Extract first half of string │ └── script.js │ ├── Get first 3 character of string │ └── script.js │ ├── Get last n character of String │ └── script.js │ ├── Get nth character of string │ ├── index.html │ └── script.js │ ├── Get type of value │ ├── index.html │ └── script.js │ ├── How many times does a character occur │ └── script.js │ ├── Multiplication, division, and comparison operators │ └── script.js │ ├── Remove last n characters of string │ └── script.js │ ├── Return the percentage of a number │ └── script.js │ ├── Round a number to 2 decimal places │ └── script.js │ ├── Split a number into its digits │ └── script.js │ ├── Sum two numbers │ ├── index.html │ └── script.js │ └── remove first n character of string │ ├── index.htm │ └── scritp.js ├── LICENSE ├── Practice In JavaScript Progrmas ├── May │ ├── day00_1May │ │ ├── question1.js │ │ └── question2.js │ ├── day1 │ │ ├── index.js │ │ └── practice.js │ ├── day10_29may │ │ ├── hcf.js │ │ ├── index.html │ │ ├── index.js │ │ ├── javaSc.js │ │ ├── javasc2.js │ │ ├── script.js │ │ ├── string.js │ │ └── style.css │ ├── day11_31May │ │ └── script.js │ ├── day2 │ │ └── variable.js │ ├── day4 │ │ └── index.js │ ├── day5 │ │ ├── index.html │ │ ├── index.js │ │ ├── index2.html │ │ ├── myWeb.html │ │ ├── myWeb.js │ │ └── myweb.css │ ├── day6 │ │ ├── index.html │ │ └── index.js │ ├── day7_18May │ │ ├── index.html │ │ ├── script.js │ │ └── script2.js │ ├── day8_23May │ │ └── index.html │ └── day9_28may │ │ ├── game.js │ │ └── script.js ├── august │ ├── day34_1august │ │ ├── class.js │ │ ├── new keyword.js │ │ ├── object.js │ │ └── this.js │ ├── day35_02august │ │ └── sort.js │ ├── day36_03August │ │ ├── maximum unique elements in matrix.js │ │ ├── pattern star │ │ │ ├── Downward Triangle Star Pattern.js │ │ │ ├── Hollow Triangle Star Pattern.js │ │ │ ├── Hollow square pattern.js │ │ │ ├── Right triangle pattern.js │ │ │ ├── left triangle pattern.js │ │ │ ├── pyramid pattern.js │ │ │ └── square star printing.js │ │ └── sum of diogonal elements.js │ ├── day37_04August │ │ └── splice.js │ ├── day38_05august │ │ └── prototype.js │ ├── day39_08august │ │ ├── call back hell.js │ │ └── temp.js │ ├── day40_10aug │ │ └── missing nearest element.js │ ├── day41_11aug │ │ ├── Maximum sum subarray of size k - O(n + k).js │ │ ├── Maximum sum subarray of size k- O(n^2).js │ │ ├── algorithms │ │ │ ├── bubble sort.js │ │ │ ├── insertion sort.js │ │ │ ├── merge sort.js │ │ │ ├── selection sort.js │ │ │ └── stable selection sort.js.js │ │ ├── bubble sort.js │ │ ├── selection sort.js │ │ └── stable selection sort.js │ ├── day42_12august │ │ ├── isertion sort.js │ │ ├── local compare.js │ │ ├── merge sort.js │ │ └── merge two sorted array.js │ ├── day43_13August │ │ ├── Merge k-sorted arrays of size n(Merge cards).js │ │ ├── count inversion.js │ │ ├── kth smallest number.js │ │ ├── median of two sorted Array.js │ │ ├── merge sort.js │ │ └── quick sort.js │ ├── day44_14August │ │ ├── number in array test 2.js │ │ ├── optimize │ │ │ ├── index.html │ │ │ ├── script.js │ │ │ └── style.css │ │ └── test 1.js │ ├── day45_16August │ │ └── find element persence times.js │ ├── day46_17August │ │ └── generators.js │ ├── day48_19Aug │ │ └── opposite sign.js │ └── day50_21Aug │ │ └── question.js ├── july │ ├── day16_1July │ │ ├── Array_Sort.js │ │ ├── Check_Array_Is_In_Assending_or_Dessending_Order.js │ │ ├── arrayTemp.js │ │ ├── checkSortedArray.js │ │ ├── find_the_list_of_numbers.js │ │ ├── isArraySorted.js │ │ └── tempCodeRunnerFile.js │ ├── day17_2July │ │ ├── number.js │ │ ├── subarray.js │ │ ├── table.js │ │ └── tableUsingRecursion.js │ ├── day18_4July │ │ ├── returnSort.js │ │ └── smallest.js │ ├── day19_5July │ │ ├── anagram.js │ │ └── factors.js │ ├── day21_13July │ │ ├── bracket.js │ │ ├── prime.js │ │ ├── sum.js │ │ └── sumOfSubarray.js │ ├── day24_18July │ │ ├── accessing_an_array.js │ │ ├── array.js │ │ ├── day20_8July │ │ │ └── palindrome.js │ │ ├── day22_14July │ │ │ ├── addingSubArray.js │ │ │ ├── dublicateElement.js │ │ │ ├── isprime.js │ │ │ └── subarray.js │ │ ├── day23_15July │ │ │ ├── mergeSort.js │ │ │ ├── selection_Sorting.js │ │ │ └── subArray.js │ │ ├── forEach.js │ │ ├── forLoop.js │ │ ├── functionExpression.js │ │ ├── merge_sort.js │ │ └── primeornot.js │ ├── day25_19July │ │ ├── anagram.js │ │ ├── mergeSorting.js │ │ └── temp.js │ ├── day26_20July.js │ │ ├── inversion.js │ │ ├── inversion_nlogn_timecomplexity.js │ │ └── medianOfTwoSortedArray.js │ ├── day27_21July │ │ ├── deepak_Problem.js │ │ └── test_result.js │ ├── day28_22July.js │ │ ├── bubblesort.js │ │ ├── insertionSort.js │ │ ├── pivot.js │ │ ├── quickSortAlgo.js │ │ └── selectionSort.js │ ├── day29_24July │ │ ├── ArrayMultiplication.js │ │ ├── even_odd_array.js │ │ ├── kth_smallest_num.js │ │ ├── median%20OF%20Array.js │ │ ├── quickSort.js │ │ └── triplet_sum_of_three_numbers_to_get_target_valuse.js │ ├── day30_28July │ │ └── moving array element.js │ ├── day31_29July │ │ └── check square.js │ ├── day32_30July │ │ ├── hash map.js │ │ ├── rotate 90 degree matrix.js │ │ ├── transpose of a matrix.js │ │ └── transpose of matrix in place algorithm.js │ └── day33_31July │ │ ├── data reference.js │ │ ├── quick sort algo.js │ │ ├── quick sort.js │ │ └── scope.js └── june │ ├── day11_1_6th_june │ └── assignment1.js │ ├── day12_1_19nth_june │ ├── map_in_javascript.js │ └── unique_number_in_array.js │ ├── day12_20June │ ├── alphabate.js │ ├── fuctionReturnAnotherFuction.js │ ├── input.js │ ├── script.js │ └── swati.js │ ├── day13_25June │ ├── fabonic.js │ ├── factorial.js │ ├── forEach.js │ ├── increasementOderNumber.js │ ├── palindrone.js │ ├── prime.js │ └── temp.js │ ├── day14_26June │ ├── codeplito.js │ ├── debug.js │ ├── freeze.js │ ├── palindrome.js │ ├── palindrone.js │ ├── palindrone.zip │ ├── tempCodeRunnerFile.js │ ├── test.js │ └── test2.js │ └── day15_27June │ ├── composability.js │ ├── curryingAdd.js │ └── higherOrder.js ├── README.md ├── ReLevel By Unacademy ├── Advance DSA │ ├── 02 November Problem Solving on Binary SEarch │ │ ├── Aggressive Cows.js │ │ └── assignment │ │ │ └── assignment1.js │ ├── 04 Nov Binary Search │ │ ├── find the number.js │ │ └── find x sum.js │ ├── 05 Nov │ │ └── max 0.js │ ├── 07 November revise sorting │ │ └── roti and paratha.js │ ├── 10 Oct Array and Object │ │ ├── Arrays_and_Objects_Notes.pdf │ │ └── revision.js │ ├── 10 dec BT │ │ ├── Breadth first search.js │ │ └── Defth first seach.js │ ├── 11 Oct Advanced Problem Solving Arrays and Objects │ │ ├── Assignment │ │ │ ├── Assignment 1.js │ │ │ ├── Assignment 2.js │ │ │ └── Assignment Solutions.pdf │ │ ├── Problem_Solving_On_Arrays_and_Objects.pdf │ │ ├── class desk.pdf │ │ ├── class practice │ │ │ ├── Anagram.js │ │ │ ├── First non-repeating character.js │ │ │ ├── Print frequency of element in the string.js │ │ │ ├── Shift Negative elements to the end of an array.js │ │ │ └── Subarray with sum 0.js │ │ ├── pre read.pdf │ │ └── self practice │ │ │ ├── Cyclically rotate an array by one.js │ │ │ ├── Longest Consecutive Sequence.js │ │ │ ├── anagram with in built function │ │ │ └── anagram.js │ ├── 14 Nov linked list │ │ └── linked list.js │ ├── 2 dec linked list │ │ └── linked list.js │ ├── 25 Nov stack │ │ ├── immediateSmallerElement.js │ │ ├── nextLargerElement.js │ │ ├── previous smallest element.js │ │ └── temp.js │ ├── 27 Nov │ │ └── test │ │ │ ├── Purchase the bike or not.js │ │ │ └── numbers are in this range.js │ ├── 28 Oct BTS │ │ ├── 1st equal or greater to x.js │ │ ├── Assignment │ │ │ └── first and last element in an Sorted Array.js │ │ ├── First and Last position of an element in a sorted array.js │ │ ├── binaray search.js │ │ ├── find repeating element using binary SEarch.js │ │ └── milestone test.js │ ├── 29 OCT BTS │ │ └── number of rotation in Rotated.js │ ├── heap │ │ └── max heap.js │ └── recursion revision │ │ ├── binaray search.js │ │ ├── bubble sort using recursion.js │ │ ├── factorial.js │ │ ├── fibonachi.js │ │ ├── find element index from array .js │ │ ├── isArraySorted.js │ │ ├── lexciOrder.js │ │ ├── lexo.js │ │ ├── merge two sorted array using recursion.js │ │ ├── monkey coin.js │ │ ├── n natural number in decreasing order.js │ │ ├── n natural numbers.js │ │ ├── pattern in reverse.js │ │ ├── pattern printing.js │ │ ├── possible subsequencel.js │ │ ├── remove dublicates in String using.js │ │ ├── star printing using recursion.js │ │ └── sumofDigits.js ├── html │ ├── assignment │ │ ├── 10Aug │ │ │ └── Create a basic homepage with four list items ensuring all text are emboldened │ │ │ │ ├── index.html │ │ │ │ └── style.css │ │ ├── 16Aug │ │ │ └── index.html │ │ ├── 6aug │ │ │ ├── b.jpg │ │ │ ├── e_commerce_login_page.html │ │ │ └── login.html │ │ └── 8aug │ │ │ ├── aman.jpg │ │ │ ├── computer pic.jpg │ │ │ ├── desktop pic.jpg │ │ │ ├── desktop pic2.jpg │ │ │ ├── istockphoto-1335422806-1024x1024.jpg │ │ │ ├── product.html │ │ │ ├── style.css │ │ │ └── vecteezy_abstract-white-podium-with-wall-scene-for-product-display_8694447.jpg │ └── classDesk │ │ ├── 12Aug │ │ └── index.html │ │ ├── 16Aug │ │ └── parrelx-bg.html │ │ ├── 22 Aug │ │ └── js │ │ │ ├── call back hell.js │ │ │ ├── calling external api.js │ │ │ ├── promise.js │ │ │ ├── set time out.js │ │ │ └── setInterval.js │ │ ├── 6Aug │ │ ├── part 1.html │ │ ├── part1.pdf │ │ └── surver.html │ │ └── 8aug │ │ ├── practice.htm │ │ └── prime.htm ├── javascript │ ├── Assignments │ │ ├── 11JUne │ │ │ ├── assignment1.js │ │ │ └── assignment2.js │ │ ├── 16June │ │ │ ├── assignment1.js │ │ │ └── assignment2.js │ │ ├── 18June │ │ │ ├── assignment.js │ │ │ └── assignment2.js │ │ ├── 1August │ │ │ ├── Assignment1.js │ │ │ └── assignment2.js │ │ ├── 1june │ │ │ ├── assignment1.js │ │ │ └── assignment2.js │ │ ├── 20June │ │ │ ├── Assignment1.js │ │ │ ├── assignment2.js │ │ │ ├── assignment3.js │ │ │ └── assignmet4.js │ │ ├── 20May │ │ │ ├── Assignment1 │ │ │ │ ├── palindromes.js │ │ │ │ └── tempCodeRunnerFile.js │ │ │ └── Assignment2.js │ │ │ │ └── possitive_integer.js │ │ ├── 21June │ │ │ ├── assignment1.js │ │ │ ├── assignment2.js │ │ │ ├── assignment3.js │ │ │ └── assignment4.js │ │ ├── 21May │ │ │ ├── assignment1.js │ │ │ └── assignment2.js │ │ ├── 23May │ │ │ ├── Assignment1 │ │ │ │ ├── index.html │ │ │ │ └── script.js │ │ │ └── Assignment2 │ │ │ │ └── palindrome.js │ │ ├── 28May │ │ │ ├── Assignment1.js │ │ │ └── assignment2.js │ │ ├── 3June │ │ │ ├── assignment1.js │ │ │ └── assignment2.js │ │ ├── 4June │ │ │ ├── assignment 2.js │ │ │ └── assingnment 1.js │ │ ├── Array │ │ │ ├── alien_language.js │ │ │ ├── longest_SubArray.js │ │ │ └── maggic_square.js │ │ └── conditional │ │ │ ├── 75%_minimum.js │ │ │ ├── conditional 3.js │ │ │ ├── conditional 4.js │ │ │ └── conditional2.js │ ├── Class Desk │ │ ├── May │ │ │ ├── 23May │ │ │ │ ├── question1.js │ │ │ │ ├── question10.js │ │ │ │ ├── question11.js │ │ │ │ ├── question12.js │ │ │ │ ├── question13.js │ │ │ │ ├── question2.js │ │ │ │ ├── question3.js │ │ │ │ ├── question4.js │ │ │ │ ├── question5.js │ │ │ │ ├── question6.js │ │ │ │ ├── question7.js │ │ │ │ ├── question8.js │ │ │ │ ├── question9.js │ │ │ │ └── tempCodeRunnerFile.js │ │ │ ├── 25thMay │ │ │ │ ├── addition_without_+_.js │ │ │ │ ├── bob_the_builder.js │ │ │ │ ├── distance_to_office.js │ │ │ │ ├── factor_of_60.js │ │ │ │ ├── hight_of_prism.js │ │ │ │ ├── lcm.js │ │ │ │ ├── nth_fibonachi.js │ │ │ │ ├── power_of_number.js │ │ │ │ ├── sum_Of_prime.js │ │ │ │ └── sum_of_digits.js │ │ │ ├── 27May │ │ │ │ ├── binomialCoefficient.js │ │ │ │ ├── calculate_n!.js │ │ │ │ ├── equalDistribution.js │ │ │ │ ├── power.js │ │ │ │ ├── square.js │ │ │ │ ├── table.js │ │ │ │ ├── trailingZeros.js │ │ │ │ └── triangle.js │ │ │ ├── 28May │ │ │ │ ├── Permutation_Divisible_by_60.js │ │ │ │ ├── class.js │ │ │ │ ├── power_Of_Number.js │ │ │ │ ├── sum_of_Digits.js │ │ │ │ └── sum_of_Prime.js │ │ │ └── 31May │ │ │ │ └── Data Structures Arrays and Objects (Part-1) │ │ │ │ └── output_Guess.js │ │ ├── august │ │ │ ├── 1August OOP │ │ │ │ ├── OOPs type │ │ │ │ │ ├── abstraction.js │ │ │ │ │ ├── encapsulation.js │ │ │ │ │ ├── inheritance.js │ │ │ │ │ └── polymorphism.js │ │ │ │ ├── class.js │ │ │ │ ├── new keyword.js │ │ │ │ ├── object.js │ │ │ │ ├── prototypes.js │ │ │ │ └── this.js │ │ │ └── 3August Asyc programming part 1 │ │ │ │ ├── 3 august.pdf │ │ │ │ ├── call queue.js │ │ │ │ ├── callback fuction.js │ │ │ │ ├── callstack.js │ │ │ │ ├── prototype.js │ │ │ │ ├── setTimeInterval.js │ │ │ │ └── setTimeout.js │ │ └── june │ │ │ ├── 11june │ │ │ ├── diagonal matrix.js │ │ │ ├── find element.js │ │ │ ├── maximum element.js │ │ │ ├── print array in spiral form.js │ │ │ ├── second maximum element.js │ │ │ ├── sum of column.js │ │ │ ├── unique element using hasmap algorithm.js │ │ │ └── unique element.js │ │ │ ├── 18June │ │ │ ├── array length.js │ │ │ ├── closure.js │ │ │ ├── clouser examples.js │ │ │ ├── curryMultiply.js │ │ │ ├── de structuring object.js │ │ │ ├── find element in array.js │ │ │ ├── guess output.js │ │ │ ├── object notation.js │ │ │ ├── pass by reference.js │ │ │ ├── pass by value.js │ │ │ ├── set Time out function.js │ │ │ ├── sort an array with custom number.js │ │ │ └── sort containing string.js │ │ │ ├── 1June │ │ │ └── object destructing │ │ │ │ ├── question1.js │ │ │ │ ├── question10.js │ │ │ │ ├── question11.js │ │ │ │ ├── question2.js │ │ │ │ ├── question3.js │ │ │ │ ├── question4.js │ │ │ │ ├── question5.js │ │ │ │ ├── question6.js │ │ │ │ ├── question7.js │ │ │ │ ├── question8.js │ │ │ │ ├── question9.js │ │ │ │ └── without_destructuring.js │ │ │ ├── 20June │ │ │ ├── class desk.pdf │ │ │ ├── currying.js │ │ │ ├── function.js │ │ │ ├── higher order function.js │ │ │ ├── iife.js │ │ │ └── input.js │ │ │ ├── 21June │ │ │ ├── classdesk 21 june.pdf │ │ │ └── json.js │ │ │ ├── 22June │ │ │ ├── class desk 22 june.pdf │ │ │ ├── find all the elements which occur in both the arrays.js │ │ │ ├── majority elements.js │ │ │ ├── pair of elment is equal to N.js │ │ │ ├── plant and weed.js │ │ │ ├── print subarrays.js │ │ │ ├── set.js │ │ │ ├── sum of triplet element for a number.js │ │ │ ├── unique element in 2D array.js │ │ │ └── unique element.js │ │ │ ├── 25June │ │ │ ├── Maximize Pairwise Sum.js │ │ │ └── calss desk 25 june.pdf │ │ │ ├── 3June │ │ │ ├── maximum_profit_stock.js │ │ │ ├── minimum_and_maximum_element.js │ │ │ ├── reverseArray.js │ │ │ ├── reverse_sub_array_to_sort_array.js │ │ │ └── sort.js │ │ │ ├── 4June │ │ │ ├── maximum profit stock.js │ │ │ ├── minimum and maximum element.js │ │ │ ├── pime numbers.js │ │ │ ├── reverse pyramid.js │ │ │ └── single digit sum.js │ │ │ ├── 6june │ │ │ ├── Shift Negative elements to the end of an array.js │ │ │ ├── cycling rotate array.js │ │ │ ├── longest consuctive elements.js │ │ │ ├── reverse Array.js │ │ │ ├── reverse sub array.js │ │ │ └── spare square.js │ │ │ └── 8June │ │ │ ├── Transpose of a matrix(In-place).js │ │ │ ├── add remove delete element.js │ │ │ ├── create a 2D array.js │ │ │ ├── explode bombs.js │ │ │ ├── foreach.js │ │ │ ├── matrix multiplication.js │ │ │ ├── printwave.js │ │ │ ├── rotate an array 90 degree.js │ │ │ ├── spiral printing.js │ │ │ └── transpose of a matrix.js │ ├── examTest │ │ ├── Counting Valleys.js │ │ ├── DIVISIBILITY BY K.js │ │ ├── Divisible Sum Pairs.js │ │ ├── Drawing Book.js │ │ ├── Frontend Development Test Round 1.js │ │ ├── MINI Xor.js │ │ ├── Mini-Max Sum.js │ │ ├── More the merrier.js │ │ ├── NP problem.js │ │ ├── Question Name Repaint.js │ │ ├── Smallest array.js │ │ ├── The Absolute Path.js │ │ ├── arrayPair.js │ │ ├── biderectional_Road.js │ │ ├── evendistribution.js │ │ ├── index.htm │ │ ├── odd prefix 1.js │ │ ├── path queries.js │ │ ├── police_of_Berland.js │ │ ├── powerful triplet.js │ │ ├── ranking elections.js │ │ ├── script.js │ │ ├── sorting machine.js │ │ ├── subarray And.js │ │ ├── subsequence.js │ │ ├── superior_minions.js │ │ ├── trip of six friends.js │ │ └── x-mas array.js │ ├── notes_for_javascript_with_code │ │ ├── basic.js │ │ └── input │ ├── package-lock.json │ └── package.json └── mcq.js ├── geeks for geeks solution ├── Cyclically rotate an array by one.js ├── Dsa │ ├── Array │ │ ├── Max Min.js │ │ └── binary search.js │ ├── Next Greater Element.js │ └── question1.js ├── First negative integer in every window of size k.js ├── Generate Binary Numbers.js ├── Maximum of all subarrays of size k.js ├── Reverse First K elements of Queue.js ├── Subarray with given sum.js ├── bit magic │ └── Power of 2.js └── conunt inversion.js ├── hackerrank challenge ├── DS │ ├── array │ │ ├── array manipulation.js │ │ ├── dynamic array.js │ │ ├── left rotation.js │ │ └── spares Arrays.js │ ├── linked list │ │ └── Insert a Node at the Tail of a Linked List.js │ └── stack │ │ ├── Poisonous Plants.js │ │ ├── and xor or.js │ │ ├── balanced brackets.js │ │ └── witer.js ├── MountBlue Job Challenge │ ├── ACM ICPC Team.JS │ ├── Between Two Sets.js │ ├── Bill Division.js │ ├── Breaking the Records.js │ ├── Caesar Cipher.js │ ├── CamelCase.js │ ├── Compare the Triplets.js │ ├── Counting Sort 2.js │ ├── Day of the Programmer.js │ ├── Electronics Shop.js │ ├── Flipping bits.js │ ├── Forming a Magic Square.js │ ├── Game of Thrones - I.js │ ├── Halloween Sale.js │ ├── Jumping on the Clouds Revisited.js │ ├── Largest Permutation.js │ ├── Making Anagrams.js │ ├── Mark and Toys.js │ ├── Mars Exploration.js │ ├── Max Min.js │ ├── Minimum Absolute Difference in an Array.js │ ├── Missing Numbers.js │ ├── Modified Kaprekar Numbers.js │ ├── Number Line Jumps.js │ ├── Partition.js │ ├── Permuting Two Arrays.js │ ├── Recursive Digit Sum.js │ ├── Running Time of Algorithms.js │ ├── Sales by Match.js │ ├── Sansa and XOR.js │ ├── Sherlock and The Beast.js │ ├── Sherlock and the Valid String.js │ ├── Simple Array Sum.js │ ├── Staircase.js │ ├── Strange Counter.js │ ├── Subarray Division.js │ ├── Super Reduced String.js │ ├── The Grid Search.js │ ├── The Love-Letter Mystery.js │ ├── The Time in Words.js │ ├── Viral Advertising.js │ ├── angry professor.js │ ├── append and delete.js │ ├── beautifulDays.js │ ├── beautifulTriplets.js │ ├── cavity Map.js │ ├── chocolateFeast.js │ ├── circular array rotation.js │ ├── climbing leader board.js │ ├── closest numbers.js │ ├── correctness and loop invarints.js │ ├── counter game.js │ ├── cutTheSticks.js │ ├── encryption.js │ ├── equalizeArray.js │ ├── ermutationEquation.js │ ├── funny string.js │ ├── gridChallenge.js │ ├── hurdleRace.js │ ├── insertion sort 1.js │ ├── insertion sort 2.js │ ├── jim orders.js │ ├── minimumDistances.js │ ├── pangrams.js │ ├── plus minus.js │ ├── sepreate numbers.js │ ├── squares.js │ ├── strong password.js │ ├── sumXor.js │ ├── taum and B'day.js │ └── time conversion.js └── algorithms │ ├── bit manipulation │ ├── Counter game.js │ └── Lonely Integer.js │ └── string │ ├── Caesar Cipher.js │ ├── CamelCase.js │ ├── Gemstones.js │ ├── Highest Value Palindrome.js │ ├── Palindrome Index.js │ ├── Separate the Numbers.js │ ├── Super Reduced String.js │ ├── The Love-Letter Mystery.js │ ├── Weighted Uniform Strings.js │ ├── anagram.js │ ├── funny Strings.js │ ├── pangram.js │ ├── strong password.js │ └── two Characters.js ├── js advance ├── apicall.html ├── async │ ├── automatic background color changer.html │ ├── clock.html │ ├── color choice game.html │ └── key speed.html └── different types ofselectors │ ├── index.html │ ├── script.css │ └── style.css ├── leet Code ├── 1. Two Sum.js ├── 102. Binary Tree Level Order Traversal.js ├── 1020. Number of Enclaves.js ├── 1089. Duplicate Zeros.js ├── 11. Container With Most Water.js ├── 1108. Defanging an IP Address.js ├── 118. Pascal's Triangle.js ├── 12. Integer to Roman.js ├── 121. Best Time to Buy and Sell Stock.js ├── 128. Longest Consecutive Sequence.js ├── 1295. Find Numbers with Even Number of Digits.js ├── 134. Gas Station.js ├── 1342. Number of Steps to Reduce a Number to Zero.js ├── 1347. Minimum Number of Steps to Make Two Strings Anagram.js ├── 135. Candy.js ├── 14. Longest Common Prefix.js ├── 144. Binary Tree Preorder Traversal.js ├── 1446. Consecutive Characters.js ├── 145. Binary Tree Postorder Traversal.js ├── 1451. Rearrange Words in a Sentence.js ├── 1486. XOR Operation in an Array.js ├── 1498. Number of Subsequences That Satisfy the Given Sum Condition.js ├── 15. 3Sum.js ├── 150. Evaluate Reverse Polish Notation.js ├── 1544. Make The String Great.js ├── 1550. Three Consecutive Odds.js ├── 162. Find Peak Element.js ├── 1657. Determine if Two Strings Are Close.js ├── 167. Two Sum II - Input Array Is Sorted.js ├── 1678. Goal Parser Interpretation.js ├── 1684. Count the Number of Consistent Strings.js ├── 1704. Determine if String Halves Are Alike.js ├── 1720. Decode XORed Array.js ├── 1748. Sum of Unique Elements.js ├── 1832. Check if the Sentence Is Pangram.js ├── 189. Rotate Array.js ├── 191. Number of 1 Bits.js ├── 2. Add Two Numbers.js ├── 20. Valid Parentheses.js ├── 200. Number of Islands.js ├── 2011. Final Value of Variable After Performing Operations.js ├── 21. Merge Two Sorted Lists.js ├── 2114. Maximum Number of Words Found in Sentences.js ├── 2133. Check if Every Row and Column Contains All Numbers.js ├── 217. Contains Duplicate.js ├── 2177. Find Three Consecutive Integers That Sum to a Given Number.js ├── 22. Generate Parentheses.js ├── 220. Contains Duplicate III.js ├── 2202. Maximize the Topmost Element After K Moves.js ├── 2240. Number of Ways to Buy Pens and Pencils.js ├── 225. Implement Stack using Queues.js ├── 229. Majority Element II.js ├── 230. Kth Smallest Element in a BST.js ├── 2300. Successful Pairs of Spells and Potions.js ├── 2315. Count Asterisks.js ├── 232. Implement Queue using Stacks.js ├── 239. Sliding Window Maximum.js ├── 2405. Optimal Partition of String.js ├── 242. Valid Anagram.js ├── 2454. Next Greater Element IV.js ├── 2460. Apply Operations to an Array.js ├── 26. Remove Duplicates from Sorted Array.js ├── 2620. Counter.js ├── 268. Missing Number.js ├── 27. Remove Element.js ├── 278. First Bad Version.js ├── 283. Move Zeroes.js ├── 3. Longest Substring Without Repeating Characters.js ├── 32. Longest Valid Parentheses.js ├── 328. Odd Even Linked List.js ├── 33. Search in Rotated Sorted Array.js ├── 34. Find First and Last Position of Element in Sorted Array.js ├── 344. Reverse String.js ├── 35. Search Insert Position.js ├── 372. Super Pow.js ├── 383. Ransom Note.js ├── 387. First Unique Character in a String.js ├── 4. Median of Two Sorted Arrays.js ├── 42. Trapping Rain Water.js ├── 451. Sort Characters By Frequency.js ├── 463. Island Perimeter.js ├── 485. Max Consecutive Ones.js ├── 49. Group Anagrams.js ├── 496. Next Greater Element I.js ├── 5. Longest Palindromic Substring.js ├── 50. Pow(x, n).js ├── 503. Next Greater Element II.js ├── 532. K-diff Pairs in an Array.js ├── 54. Spiral Matrix.js ├── 540. Single Element in a Sorted Array.js ├── 541. Reverse String II.js ├── 55. Jump Game.js ├── 557. Reverse Words in a String III.js ├── 567. Permutation in String.js ├── 58. Length of Last Word.js ├── 633. Sum of Square Numbers.js ├── 64. Minimum Path Sum.js ├── 66. Plus One.js ├── 668. Kth Smallest Number in Multiplication Table.js ├── 67. Add Binary.js ├── 69. Sqrt(x).js ├── 695. Max Area of Island.js ├── 7. Reverse Integer.js ├── 704. Binary Search.js ├── 71. Simplify Path.js ├── 717. 1-bit and 2-bit Characters.js ├── 73. Set Matrix Zeroes.js ├── 733. Flood Fill.js ├── 735. Asteroid Collision.js ├── 74. Search a 2D Matrix.js ├── 78 subsets.js ├── 8. String to Integer (atoi).js ├── 81. Search in Rotated Sorted Array II.js ├── 876. Middle of the Linked List.js ├── 88. Merge Sorted Array.js ├── 881. Boats to Save People.js ├── 9. Palindrome Number.js ├── 90. subsets II.js ├── 907. Sum of Subarray Minimums.js ├── 931. Minimum Falling Path Sum.js ├── 938. Range Sum of BST.js ├── 94. Binary Tree Inorder Traversal.js ├── 977. Squares of a Sorted Array.js ├── Contains_Duplicate_II.js ├── alindrome_Linked_List.js ├── contanins_Duplicate.js ├── maximum subarray.js ├── medain of two sorted array.js ├── roman_to_decima.js ├── sum_of_two_num.js ├── temp.js └── tempCodeRunnerFile.js ├── package-lock.json ├── package.json ├── practice for FEd └── aug │ ├── day46_17Aug │ ├── index.html │ ├── navbar-background.jpg │ └── style.css │ ├── day47_18Aug │ └── Expand the Media Gallery app to have the images pop when hovered upon.js │ │ ├── districk koderma loga.png │ │ └── index.html │ └── day49_20aug │ └── index.html ├── practice from relevel └── Relevel round 2 Practice Problem │ └── Redistribution │ ├── Redistribution.js │ ├── question.png │ └── read.md ├── tailwindcss ├── another responsive card │ ├── dist │ │ ├── index.html │ │ └── style.css │ ├── src │ │ └── input.css │ └── tailwind.config.js ├── card │ ├── dist │ │ ├── index.html │ │ └── style.css │ ├── src │ │ └── input.css │ └── tailwind.config.js └── responsive card │ ├── dist │ ├── index.html │ └── output.css │ ├── src │ └── input.css │ └── tailwind.config.js ├── temp.js └── tempCodeRunnerFile.js /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Attach", 5 | "port": 9229, 6 | "request": "attach", 7 | "skipFiles": [ 8 | "/**" 9 | ], 10 | "type": "node" 11 | }, 12 | 13 | 14 | 15 | { 16 | "type": "pwa-chrome", 17 | "name": "4", 18 | "request": "launch", 19 | "url": "4" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Self 2 | -------------------------------------------------------------------------------- /DSA in javaScript/backtracking/Backtracking in array.js: -------------------------------------------------------------------------------- 1 | // Online Javascript Editor for free 2 | // Write, Edit and Run your Javascript code using JS Online Compiler 3 | 4 | console.log("Welcome to Programiz!"); 5 | 6 | function back (arr, val, indx, len ){ 7 | if(indx === len) { 8 | console.log(arr); 9 | return; 10 | } 11 | 12 | arr[indx] = val; 13 | back(arr, val + 1, indx +1, len) 14 | arr[indx] = arr[indx] - 2; 15 | 16 | 17 | } 18 | 19 | let arr = [] 20 | 21 | back(arr, 1, 0, 5) 22 | console.log(arr) 23 | -------------------------------------------------------------------------------- /DSA in javaScript/backtracking/find subsets.js: -------------------------------------------------------------------------------- 1 | let string = "abc"; 2 | let arr = []; 3 | 4 | 5 | subset(string, "", 0) 6 | console.log(arr); 7 | 8 | 9 | function subset(str, s, indx) { 10 | 11 | if (indx >= str.length) { 12 | arr.push(s); 13 | return; 14 | } 15 | 16 | 17 | 18 | 19 | subset(str, s + str[indx], indx + 1); 20 | subset(str, s, indx + 1); 21 | 22 | 23 | 24 | } -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/1342. Number of Steps to Reduce a Number to Zero.js: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/description/ 2 | /** 3 | * @param {number} num 4 | * @return {number} 5 | */ 6 | var numberOfSteps = function (num) { 7 | let count = 0; 8 | 9 | while (num > 0) { 10 | 11 | num = num & 1 === 1 ? --num : num >> 1; 12 | count++; 13 | // console.log(num); 14 | 15 | } 16 | return count; 17 | 18 | }; 19 | 20 | 21 | console.log(numberOfSteps(13)) -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/148. XOR Operation in an Array.js: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/xor-operation-in-an-array/description/ 2 | 3 | /** 4 | * @param {number} n 5 | * @param {number} start 6 | * @return {number} 7 | */ 8 | var xorOperation = function (n, start) { 9 | let ans = 0; 10 | 11 | for (let i = 0; i < n; i++) { 12 | 13 | ans ^= start + 2 * i; 14 | 15 | } 16 | 17 | return ans; 18 | }; -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/1684. Count the Number of Consistent Strings.js: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/count-the-number-of-consistent-strings/description/ 2 | 3 | /** 4 | * @param {string} allowed 5 | * @param {string[]} words 6 | * @return {number} 7 | */ 8 | var countConsistentStrings = function (allowed, words) { 9 | 10 | 11 | let map = new Map(); 12 | 13 | for (let i of allowed) map.set(i); 14 | 15 | let count = 0; 16 | for (let i of words) { 17 | 18 | let consistent = true; 19 | for (let j of i) { 20 | 21 | if (!map.has(j)) { 22 | consistent = false; 23 | break; 24 | } 25 | } 26 | if (consistent) count++; 27 | } 28 | return count; 29 | 30 | }; -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/1720. Decode XORed Array.js: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/decode-xored-array/description/ 2 | /** 3 | * @param {number[]} encoded 4 | * @param {number} first 5 | * @return {number[]} 6 | */ 7 | var decode = function (encoded, first) { 8 | 9 | const orignal_array = [first]; 10 | 11 | for (let i = 0; i < encoded.length; i++) { 12 | 13 | orignal_array.push(orignal_array[i] ^ encoded[i]); 14 | } 15 | return orignal_array 16 | 17 | 18 | }; 19 | 20 | 21 | -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/Exceptionally odd.js: -------------------------------------------------------------------------------- 1 | // https://practice.geeksforgeeks.org/problems/find-the-odd-occurence4820/1?page=1&category[]=Bit%20Magic&sortBy=submissions 2 | 3 | 4 | 5 | function getOddOccurrence(arr, n) { 6 | //code here 7 | let ans = 0; 8 | 9 | for (let i in arr) { 10 | ans = ans ^ arr[i] 11 | console.log(ans) 12 | } 13 | return ans; 14 | } 15 | 16 | 17 | console.log(getOddOccurrence([1, 2, 3, 2, 3, 1, 3])) 18 | -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/Missing number in array.js: -------------------------------------------------------------------------------- 1 | function MissingNumber(array, n) { 2 | //code here 3 | 4 | let ans = 0; 5 | for (let i = 0; i < n - 1; i++) { 6 | 7 | ans = ans ^ array[i] ^ i + 1; 8 | } 9 | 10 | ans = ans ^ n; 11 | return ans; 12 | } 13 | 14 | 15 | const arr = [1, 2, 3, 5] 16 | 17 | console.log(MissingNumber(arr, 5)); -------------------------------------------------------------------------------- /DSA in javaScript/bit manupaltion/odd or even.js: -------------------------------------------------------------------------------- 1 | const num = 7; 2 | 3 | 4 | // 1 repersents odd 5 | console.log(num & 1 === 1 ) -------------------------------------------------------------------------------- /DSA in javaScript/divide and conqure/dac.js: -------------------------------------------------------------------------------- 1 | function dac(arr , i , j) { 2 | 3 | if(small(arr, i, j)) return solution(arr, i, j) 4 | else { 5 | 6 | let p = divide(arr, i, j); 7 | let s1 = dac(arr, i, p); 8 | let s2 = dac(arr, p + 1, j) 9 | 10 | let s = combine(s1, s2); 11 | 12 | return s; 13 | } 14 | 15 | } 16 | 17 | 18 | function solution(arr, i, j) { 19 | 20 | 21 | } 22 | 23 | function divide(arr, i, j) { 24 | 25 | 26 | } 27 | 28 | 29 | function combine(s1, s2) { 30 | 31 | 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /DSA in javaScript/divide and conqure/power of n.js: -------------------------------------------------------------------------------- 1 | function power(n, pow) { 2 | 3 | if (pow === 1) return pow * n; 4 | 5 | let mid = pow / 2; 6 | 7 | let a = power(n, parseInt(mid)); 8 | 9 | if (mid === parseInt(mid)) return a * a; 10 | 11 | else return a * power(n, Math.ceil(mid)) 12 | } 13 | 14 | console.log(power(2, 9)) -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Basic JavaScript math operators/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes 6 values (a,b,c,d,e,f) as arguments 2 | // Sum a and b 3 | // Then substract by c 4 | // Then multiply by d and divide by e 5 | // Finally raise to the power of f and return the result 6 | // Tipp: mind the order 7 | 8 | function myFunction(a, b, c, d, e, f) { 9 | 10 | return Math.pow(((((a + b) - c ) * d ) / e),f); 11 | } 12 | 13 | 14 | // myFunction(6,5,4,3,2,1) 15 | // Expected 16 | // 10.5 17 | // myFunction(6,2,1,4,2,3) 18 | // Expected 19 | // 2744 20 | // myFunction(2,3,6,4,2,3) 21 | // Expected 22 | // -8 -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Check if a number is even/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a number as argument 2 | // If the number is even, return true 3 | // Otherwise, return false 4 | 5 | function myFunction(a) { 6 | 7 | return a % 2 === 0; 8 | } 9 | 10 | /* 11 | myFunction(10) 12 | Expected 13 | true 14 | myFunction(-4) 15 | Expected 16 | true 17 | myFunction(5) 18 | Expected 19 | false 20 | myFunction(-111) 21 | Expected 22 | false 23 | */ -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Check if a number is whole number/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a number (a) as argument 2 | // If a is a whole number (has no decimal place), return true 3 | // Otherwise, return false 4 | 5 | 6 | function myFunction(a) { 7 | 8 | return (a - Math.floor(a)) === 0; 9 | } 10 | 11 | 12 | 13 | // myFunction(4) 14 | // Expected 15 | // true 16 | // myFunction(1.123) 17 | // Expected 18 | // false 19 | // myFunction(1048) 20 | // Expected 21 | // true 22 | // myFunction(10.48) 23 | // Expected 24 | // false -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Check whether a string contains another string and concatenate/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes two strings (a and b) as arguments 2 | // If a contains b, append b to the beginning of a 3 | // If not, append it to the end 4 | // Return the concatenation 5 | 6 | 7 | function myFunction(a, b) { 8 | 9 | return a.includes(b) ? b + a : a + b 10 | } 11 | 12 | /* 13 | myFunction('cheese', 'cake') 14 | Expected 15 | 'cheesecake' 16 | myFunction('lips', 's') 17 | Expected 18 | 'slips' 19 | myFunction('Java', 'script') 20 | Expected 21 | 'Javascript' 22 | myFunction(' think, therefore I am', 'I') 23 | Expected 24 | 'I think, therefore I am' 25 | */ -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Comparison operators, strict equality/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Comparison operators, strict equality 8 | 9 | 10 |

Write a function that takes two values, say a and b, as arguments 11 | Return true if the two values are equal and of the same type

12 | 13 | 14 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Comparison operators, strict equality/script.js: -------------------------------------------------------------------------------- 1 | function myFunction(a, b) { 2 | 3 | return a === b; 4 | } 5 | 6 | 7 | 8 | // myFunction(2, 3) // Expected false 9 | // myFunction(3, 3) Expected true 10 | // myFunction(1, '1') Expected false 11 | // myFunction('10', '10') Expected true -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Extract first half of string/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a string (a) as argument 2 | // Extract the first half a 3 | // Return the result 4 | 5 | 6 | 7 | 8 | function myFunction(a) { 9 | 10 | return a.slice(0, a.length / 2); 11 | } 12 | 13 | 14 | 15 | 16 | // myFunction('abcdefgh') 17 | // Expected 18 | // 'abcd' 19 | // myFunction('1234') 20 | // Expected 21 | // '12' 22 | // myFunction('gedcba') 23 | // Expected 24 | // 'ged' -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Get first 3 character of string/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a string (a) as argument 2 | // Get the first 3 characters of a 3 | // Return the result 4 | 5 | 6 | function myFunction(a) { 7 | 8 | return a.slice(0, 3); 9 | } 10 | 11 | 12 | 13 | 14 | 15 | // myFunction('abcdefg') 16 | // Expected 17 | // 'abc' 18 | // myFunction('1234') 19 | // Expected 20 | // '123' 21 | // myFunction('fgedcba') 22 | // Expected 23 | // 'fge' -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Get last n character of String/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a string as argument 2 | // Extract the last 3 characters from the string 3 | // Return the result 4 | 5 | 6 | function myFunction(str) { 7 | return str.slice(-3); 8 | } 9 | 10 | 11 | 12 | // myFunction('abcdefg') 13 | // Expected 14 | // 'efg' 15 | // myFunction('1234') 16 | // Expected 17 | // '234' 18 | // myFunction('fgedcba') 19 | // Expected 20 | // 'cba' -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Get nth character of string/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |

Write a function that takes a string (a) and a number (n) as argument
the nth character of 'a'

11 | 12 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Get nth character of string/script.js: -------------------------------------------------------------------------------- 1 | function myFunction(a, n) { 2 | 3 | return a[n - 1]; 4 | } 5 | 6 | 7 | 8 | // myFunction('abcd',1) 9 | // // Expected 10 | // // 'a' 11 | // myFunction('zyxbwpl',5) 12 | // // Expected 13 | // // 'w' 14 | // myFunction('gfedcba',3) 15 | // // Expected 16 | // // 'e' -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Get type of value/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Get type of value 8 | 9 | 10 |

Write a function that takes a value as argument Return the type of the value

11 | 12 | 13 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Get type of value/script.js: -------------------------------------------------------------------------------- 1 | function myFunction(a) { 2 | 3 | return typeof(a); 4 | } 5 | 6 | 7 | // myFunction(1) 8 | // // Expected 9 | // // 'number' 10 | // myFunction(false) 11 | // // Expected 12 | // // 'boolean' 13 | // myFunction({}) 14 | // // Expected 15 | // // 'object' 16 | // myFunction(null) 17 | // // Expected 18 | // // 'object' 19 | // myFunction('string') 20 | // // Expected 21 | // // 'string' 22 | // myFunction(['array']) 23 | // // Expected 24 | // // 'object' -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Multiplication, division, and comparison operators/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes two numbers (a and b) as arguments 2 | // If a is smaller than b, divide a by b 3 | // Otherwise, multiply both numbers 4 | // Return the resulting value 5 | 6 | 7 | 8 | function myFunction(a, b) { 9 | 10 | return a < b ? a / b : a * b 11 | } 12 | 13 | // myFunction(10, 100) 14 | // Expected 15 | // 0.1 16 | // myFunction(90, 45) 17 | // Expected 18 | // 4050 19 | // myFunction(8, 20) 20 | // Expected 21 | // 0.4 22 | // myFunction(2, 0.5) 23 | // Expected 24 | // 1 -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Remove last n characters of string/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a string (a) as argument 2 | // Remove the last 3 characters of a 3 | // Return the result 4 | 5 | 6 | 7 | function myFunction(a) { 8 | 9 | return a.slice(0, -3); 10 | } 11 | 12 | 13 | 14 | 15 | 16 | // myFunction('abcdefg') 17 | // Expected 18 | // 'abcd' 19 | // myFunction('1234') 20 | // Expected 21 | // '1' 22 | // myFunction('fgedcba') 23 | // Expected 24 | // 'fged' -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Return the percentage of a number/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes two numbers (a and b) as argument 2 | // Return b percent of a 3 | 4 | 5 | 6 | function myFunction(a, b) { 7 | 8 | return a * b / 100; 9 | } 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | // myFunction(100,50) 18 | // Expected 19 | // 50 20 | // myFunction(10,1) 21 | // Expected 22 | // 0.1 23 | // myFunction(500,25) 24 | // Expected 25 | // 125 -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Round a number to 2 decimal places/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a number (a) as argument 2 | // Round a to the 2nd digit after the comma 3 | // Return the rounded number 4 | 5 | 6 | function myFunction(a) { 7 | return Number(a.toFixed(2)); 8 | } 9 | 10 | 11 | /* 12 | myFunction(2.12397) 13 | Expected 14 | 2.12 15 | myFunction(3.136) 16 | Expected 17 | 3.14 18 | myFunction(1.12397) 19 | Expected 20 | 1.12 21 | myFunction(26.1379) 22 | Expected 23 | 26.14 24 | */ -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Split a number into its digits/script.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a number (a) as argument 2 | // Split a into its individual digits and return them in an array 3 | // Tipp: you might want to change the type of the number for the splitting 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Sum two numbers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Sum of two numbers 8 | 9 | 10 |

Q. Write a function that takes two numbers (a and b) as argument Sum a and b Return the result

11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/Sum two numbers/script.js: -------------------------------------------------------------------------------- 1 | 2 | function myFunction(a, b){ 3 | 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/remove first n character of string/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

Write a function that takes a string (a) as argument 11 |
Remove the first 3 characters of a 12 |
Return the result

13 | 14 | -------------------------------------------------------------------------------- /JsChallanger/JavaScript Basic/remove first n character of string/scritp.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a string (a) as argument 2 | // Remove the first 3 characters of a 3 | // Return the result 4 | 5 | function myFunction(a) { 6 | 7 | return a.slice(3); 8 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day00_1May/question1.js: -------------------------------------------------------------------------------- 1 | const car = [{ 2 | color: 'Black', 3 | speed: '120Kmph', 4 | brand: 'Audi', 5 | start: function () { 6 | console.log('Car started'); 7 | }, 8 | stop: function () { 9 | console.log('Car stopped'); 10 | }, 11 | }, 12 | { 13 | color: 'Red', 14 | speed: '100Kmph', 15 | brand: 'BMW', 16 | start: function () { 17 | console.log('Car started'); 18 | }, 19 | stop: function () { 20 | console.log('Car stopped'); 21 | }, 22 | },] 23 | 24 | for ([key, value] of Object.entries(car)){ 25 | console.log(`My car is ${value.brand} and color is ${value.color}`) 26 | } 27 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day00_1May/question2.js: -------------------------------------------------------------------------------- 1 | let a = readline(); 2 | 3 | console.log(a); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day1/index.js: -------------------------------------------------------------------------------- 1 | //console.log("heello"); 2 | console.log("Hello this is my fist javascript code line\n"); 3 | a = 6; 4 | if (a == 5) { 5 | console.log("printing 5"); 6 | } else { 7 | console.log("5 is not"); 8 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day1/practice.js: -------------------------------------------------------------------------------- 1 | // var ame = "aman burnwal"; 2 | // var bame = "Aman Burnwal" 3 | // console.log(ame); 4 | // console.log(bame); 5 | 6 | let i = "Aman"; 7 | console.log(i); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day10_29may/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Creating a chessboard 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day10_29may/index.js: -------------------------------------------------------------------------------- 1 | let n = parseInt(readline()); 2 | while(n--) 3 | { 4 | let arr = []; 5 | arr = readline().split(" "); 6 | var a = arr[0]; 7 | var b = arr[1]; 8 | var c = arr[2]; 9 | var l; 10 | // write your code here 11 | arr = "45 23 54" 12 | if((a > b && a < c) ||(a < b && a > c)){ 13 | console.log(a); 14 | }else if((b > a && b < c) || (b < a && b > c)){ 15 | console.log(b) 16 | }else{ 17 | console.log(c); 18 | } 19 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day10_29may/javasc2.js: -------------------------------------------------------------------------------- 1 | let num = 121; 2 | 3 | let reverse = 0; 4 | let remainder; 5 | let orignalNumber = num; 6 | 7 | while(num != 0){ 8 | remainder = num % 10; 9 | reverse = reverse * 10 + remainder; 10 | 11 | num = Math.floor(num / 10); 12 | } 13 | console.log(reverse); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day10_29may/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/Practice In JavaScript Progrmas/May/day10_29may/script.js -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day10_29may/string.js: -------------------------------------------------------------------------------- 1 | var fname = "ama"; 2 | 3 | var reversename = ""; 4 | for(let i = fname.length-1; i >= 0; i--){ 5 | 6 | reversename = reversename + fname[i]; 7 | } 8 | 9 | console.log(reversename); 10 | 11 | 12 | if(fname === reversename){ 13 | console.log("pali") 14 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day10_29may/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/Practice In JavaScript Progrmas/May/day10_29may/style.css -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day5/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

What Can JavaScript Do?

7 | 8 |

JavaScript can change HTML content.

9 |

Click here to know your result

10 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day5/index.js: -------------------------------------------------------------------------------- 1 | // var x = (3, 4, 1, 8); 2 | // console.log(x); 3 | // var x = 4; 4 | // var y = 3; 5 | 6 | // console.log('The addition of 5 + 3 is : $[x + y}'); 7 | 8 | 9 | // let num = 5; 10 | // console.log(num++); 11 | // console.log(num); 12 | // console.log(++num); 13 | 14 | // let newNum = 45; 15 | // newNum = newNum++; 16 | // const newNum2 = ++newNum 17 | 18 | // console.log(newNum2); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day5/index2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

What Can JavaScript Do?

6 | 7 |

JavaScript can change HTML attribute values.

8 | 9 |

In this case JavaScript changes the value of the src (source) attribute of an image.

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day5/myWeb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | My website 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day5/myWeb.js: -------------------------------------------------------------------------------- 1 | function myFunction() { 2 | document.getElementById("pg").innerHTML = "It is in progress"; 3 | } 4 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day5/myweb.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/Practice In JavaScript Progrmas/May/day5/myweb.css -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day6/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

Hello!

7 | 8 | 9 | 17 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day6/index.js: -------------------------------------------------------------------------------- 1 | var name = "Banti Kumar"; 2 | var name = "Aman Burnwal"; 3 | 4 | let rool = 1; 5 | //let rool = 2; // throws error cause you can't redecleare 6 | 7 | const a = 3; 8 | // a = 5; 9 | console.log(a); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day7_18May/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day7_18May/script2.js: -------------------------------------------------------------------------------- 1 | var a = prompt("Enter"); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day8_23May/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/May/day9_28may/game.js: -------------------------------------------------------------------------------- 1 | var firstName = "Banti"; 2 | var lastName = "Kumar"; 3 | 4 | var fullName = `My name is: ${firstName} ${lastName} hai `; 5 | 6 | var string = 'this is a string'; 7 | 8 | var a = `Insert a string here: ${string}`; 9 | 10 | var b = `this is your name: ${string} `; -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day34_1august/class.js: -------------------------------------------------------------------------------- 1 | // A class is a blueprint of a real-life entity. 2 | // It defines the characteristics of an Object like color, shape, size, etc 3 | 4 | 5 | //Define a class in JS 6 | class Student{ 7 | 8 | //It initializes values to your properties on object creation 9 | constructor(n, a, r){ 10 | this.name = n; 11 | this.age = a; 12 | this.rollNo = r; 13 | } 14 | 15 | getDetails(){ 16 | console.log(`The name of student is ${this.name} and age is ${this.age} and roll No is ${this.rollNo}`) 17 | } 18 | } 19 | 20 | var student1 = new Student('Jeevendra', 29, 1234) 21 | student1.getDetails() 22 | 23 | var student1 = new Student('John', 23, 4567) 24 | student1.getDetails() 25 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day34_1august/new keyword.js: -------------------------------------------------------------------------------- 1 | class Demo { 2 | msg = "hello this is a message!" 3 | } 4 | console.log(Demo.msg); // undefined 5 | // we tried to fetch the “msg” directly with Classname, so we got undefined. 6 | 7 | let newDemo = new Demo(); 8 | console.log(newDemo.msg); // hello this is a message 9 | // we try to fetch the “msg” value using object “obj”, so we got the result 10 | 11 | 12 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day35_02august/sort.js: -------------------------------------------------------------------------------- 1 | // class Mjvirus{ 2 | // constructor(array) 3 | // { 4 | // this.a = array 5 | // } 6 | // sorting() 7 | // { 8 | // return this.a.sort((a, b) => a - b) 9 | // } 10 | // } 11 | 12 | // let obj = new Mjvirus([2, 5, 1, 8]) 13 | 14 | // console.log(obj.sorting()); 15 | 16 | class Mjvirus{ 17 | constructor(array) 18 | { 19 | this.a = array 20 | } 21 | sorting() 22 | { 23 | this.a.sort((a,b) => (a-b)) 24 | } 25 | } 26 | 27 | let obj = new Mjvirus([5,4,3,2,1]) 28 | console.log(obj.sorting()) -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day36_03August/pattern star/Downward Triangle Star Pattern.js: -------------------------------------------------------------------------------- 1 | // ***** 2 | // **** 3 | // *** 4 | // ** 5 | // * 6 | 7 | 8 | let num = 5; 9 | downwardTriangleStarsPatter(num); 10 | function downwardTriangleStarsPatter(num) { 11 | 12 | for(let i = 0; i < num; i++) { 13 | let star = ""; 14 | 15 | for (let j = i; j < num; j++) { 16 | star += "*" 17 | } 18 | console.log(star); 19 | } 20 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day36_03August/pattern star/Right triangle pattern.js: -------------------------------------------------------------------------------- 1 | /** 2 | * * 3 | ** 4 | *** 5 | **** 6 | ***** 7 | */ 8 | 9 | 10 | let num = 5; 11 | rightTriangle(5); 12 | 13 | function rightTriangle(num) { 14 | let space = "", star = ""; 15 | 16 | for(let i = 1; i <= num; i++) { 17 | space = "" 18 | star = "" 19 | for (let j = 0; j < i; j++) { 20 | star += "*" 21 | } 22 | 23 | for (let k = i; k < num; k++) { 24 | space += " " 25 | } 26 | console.log(space + star); 27 | } 28 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day36_03August/pattern star/left triangle pattern.js: -------------------------------------------------------------------------------- 1 | // * 2 | // ** 3 | // *** 4 | // **** 5 | // ***** 6 | 7 | let num = 5; 8 | 9 | leftTriangle(5); 10 | 11 | function leftTriangle(num) { 12 | 13 | 14 | for(let i = 0; i < num; i++) { 15 | let star = "", space = ""; 16 | for(let j = 0; j <= i; j++ ) { 17 | star += "*"; 18 | } 19 | 20 | for (let k = i; k < num; k++) { 21 | space += " "; 22 | } 23 | 24 | console.log(star + space); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day36_03August/pattern star/pyramid pattern.js: -------------------------------------------------------------------------------- 1 | // * 2 | // *** 3 | // ***** 4 | // ******* 5 | // ********* 6 | 7 | pyramid(5); 8 | 9 | function pyramid(length) { 10 | 11 | for(let i = 0; i <= length; i++) { 12 | let star = "", space = " "; 13 | 14 | // for space 15 | for(let j = 0; j <= Math.floor(length / 2) - i; j++) { 16 | space += " "; 17 | } 18 | 19 | // for star 20 | for(let k = 1; k < i; k++) { 21 | star += "*" 22 | } 23 | 24 | console.log(space+ star +star); 25 | } 26 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day36_03August/pattern star/square star printing.js: -------------------------------------------------------------------------------- 1 | // ***** 2 | // ***** 3 | // ***** 4 | // ***** 5 | // ***** 6 | 7 | let num = 5; 8 | squareStrar(num); 9 | function squareStrar(num) { 10 | let star = "*" 11 | 12 | for(let i = 1; i < num; i++) { 13 | star += "*" 14 | } 15 | for(let i = 0; i < num; i++) { 16 | console.log(star) 17 | } 18 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day37_04August/splice.js: -------------------------------------------------------------------------------- 1 | const fruits = ["Banana", "Orange", "Apple", "Mango"]; 2 | 3 | fruits.splice(2, 0, "Lemon", "Kiwi"); 4 | 5 | var a = [1, 2, 3, 4, 5] 6 | 7 | 8 | // a.splice(0, 3); // 45 9 | console.log(a.splice(0, 3)); 10 | 11 | console.log(a); 12 | 13 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day38_05august/prototype.js: -------------------------------------------------------------------------------- 1 | function person(name) { 2 | this.name = name; 3 | console.log(this.name); 4 | } 5 | 6 | person("Banti"); 7 | 8 | person.prototype.age = function (age) { 9 | this.age = age; 10 | } 11 | 12 | // console.log(person.prototype); 13 | 14 | person.prototype.age.prototype.vot = function (vote) { 15 | this.vote = vote; 16 | } 17 | 18 | console.log(person.prototype) 19 | 20 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day39_08august/call back hell.js: -------------------------------------------------------------------------------- 1 | function greet(callbackFn) { 2 | callbackFn(); 3 | console.log('Welcome to Grandline'); 4 | } 5 | greet(function () { console.log('Hi')}); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day40_10aug/missing nearest element.js: -------------------------------------------------------------------------------- 1 | let arr = [10, 6, 7, 5, 4] 2 | 3 | missingElement(arr, 5, 6); 4 | 5 | function missingElement(arr, len, number) { 6 | let set = new Set() 7 | 8 | arr.forEach(element => set.add(element)); 9 | 10 | 11 | for (let i = 0; i < len; i++) { 12 | if (!set.has(number - i)) { 13 | console.log(number - i); 14 | return; 15 | } 16 | 17 | if (!set.has(number + i)) { 18 | console.log(number + i) 19 | return; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day41_11aug/Maximum sum subarray of size k- O(n^2).js: -------------------------------------------------------------------------------- 1 | // Maximum sum subarray of size k- O(n^2) 2 | 3 | let arr = [3, 5, 2, 1, 7, 6] 4 | console.log(maxSumSubArrayOfSizeK(arr, 3)) 5 | 6 | function maxSumSubArrayOfSizeK(arr, k) { 7 | let maxsum = 0; 8 | for(let i = 0; i <= arr.length - k; i++) { 9 | 10 | if(arr. length < k) { 11 | return false; 12 | } 13 | let sum = 0; 14 | for (let j = i; j < i + k; j++) { 15 | sum += arr[j] 16 | 17 | } 18 | 19 | if(sum > maxsum) { 20 | maxsum = sum; 21 | } 22 | } 23 | return maxsum; 24 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day41_11aug/algorithms/insertion sort.js: -------------------------------------------------------------------------------- 1 | function insertionSort(arr) { 2 | for (let i = 1; i < arr.length; i++) { 3 | 4 | let firstElementUnsortedPart = arr[i]; 5 | 6 | let j = i - 1; 7 | 8 | while (j >= 0 && arr[j] > firstElementUnsortedPart) { 9 | arr[j + 1] = arr[j]; 10 | j -= 1; 11 | } 12 | 13 | arr[j + 1] = firstElementUnsortedPart; 14 | 15 | 16 | } 17 | return arr; 18 | } 19 | let arr = [2, 4, 1, 9, 3, 8, 0]; 20 | console.log(insertionSort(arr)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day41_11aug/selection sort.js: -------------------------------------------------------------------------------- 1 | function selectionSort(arr) { 2 | let min_index; 3 | 4 | for (let i = 0; i < arr.length - 1; i++) { 5 | min_index = i; 6 | 7 | for (let j = i + 1; j < arr.length; j++) { 8 | if (arr[j] < arr[min_index]) { 9 | min_index = j; 10 | } 11 | } 12 | 13 | //Swap i, min_index 14 | let temp = arr[i]; 15 | arr[i] = arr[min_index]; 16 | arr[min_index] = temp; 17 | 18 | } 19 | 20 | return arr; 21 | } 22 | 23 | let arr = [3, 6, 1, 4, 0, 5, 6, 9] 24 | console.log(selectionSort(arr)) 25 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day45_16August/find element persence times.js: -------------------------------------------------------------------------------- 1 | // KinaSonaTujhyRabNeyBnaya 2 | 3 | 4 | let word = "KinaSonaTujhyRabNeyBnaya"; 5 | // console.log(word.split("").join(" ")) 6 | 7 | // word = word.split("").join(" "); 8 | 9 | 10 | let 11 | 12 | 13 | 14 | // wordCount(word); 15 | function wordCount(word) { 16 | let count = 0; 17 | 18 | for (let i = 0; i < word.length; i++) { 19 | if (word[i] == 'a') { 20 | count++; 21 | } 22 | 23 | } 24 | 25 | console.log(count); 26 | } 27 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day46_17August/generators.js: -------------------------------------------------------------------------------- 1 | function* generator(){ 2 | yield 1; 3 | yield 2; 4 | yield 3; 5 | } 6 | 7 | let generate = generator(); 8 | 9 | console.log(generate.next().value); 10 | console.log(generate.next().value); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/august/day48_19Aug/opposite sign.js: -------------------------------------------------------------------------------- 1 | let a = -1, b = 1; 2 | 3 | (a >= 0 && b < 0 ) || (a < 0 && b >= 0) ? console.log(true) : console.log(false); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day16_1July/Array_Sort.js: -------------------------------------------------------------------------------- 1 | array = [1, 51, 2, 52, 53, 35, 45, 32,61, 8332, 93,54, 56, 6, 31, 87]; 2 | 3 | console.log(array.sort()); 4 | 5 | // 1, 2, 31, 32, 35, 45, 51, 52, 53, 54,56, 6, 61, 8332, 87, 93 6 | 7 | 8 | array1 = ["Apple", "Cat", "Banna", "Boy"]; 9 | 10 | console.log(array1.sort()); 11 | // Apple Banna Boy Cat 12 | 13 | 14 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day16_1July/isArraySorted.js: -------------------------------------------------------------------------------- 1 | //Recursive program to check if array is sorted in increasing order 2 | // arr[i] < arr[i + 1] 3 | 4 | function isArraySorted(aarry, array_length){ 5 | if(array_length === 0 || array_length === 1){ 6 | return true; 7 | } 8 | 9 | if(aarry[array_length - 1] < aarry[array_length - 2]){ 10 | return false; 11 | } 12 | 13 | return isArraySorted(aarry, array_length - 1); 14 | 15 | } 16 | 17 | 18 | array1 = [3, 4, 5, 5,23, 49]; 19 | 20 | array1_length = array1.length; 21 | 22 | console.log(isArraySorted(array1, array1_length)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day16_1July/tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | sum = 16; 2 | preSum5 = 15; -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day17_2July/subarray.js: -------------------------------------------------------------------------------- 1 | //Print all subarrays 2 | function printSubArrays(arr) { 3 | let result = [], temp = []; 4 | for (let startPoint = 0; startPoint < arr.length; startPoint++) { 5 | for (let group = startPoint; group < arr.length; group++) { 6 | for (let i = startPoint; i <= group; i++) { 7 | temp.push(arr[i]) 8 | } 9 | result.push(temp); 10 | temp = []; 11 | } 12 | } 13 | 14 | return result 15 | } 16 | 17 | let arr = [1, 2, 3] 18 | console.log(printSubArrays(arr)) 19 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day17_2July/table.js: -------------------------------------------------------------------------------- 1 | const prompt = require('prompt-sync')(); 2 | 3 | const num = parseInt(prompt("Enter your number here ")); 4 | const time = parseInt(prompt("Enter the times of multiplication ")); 5 | 6 | function multiplication(num, time){ 7 | for(let i = 0; i <= time; i++ ){ 8 | console.log(`the multiplication of ${num} * ${i} = ${num * i}`); 9 | } 10 | } 11 | 12 | multiplication(num, time); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day17_2July/tableUsingRecursion.js: -------------------------------------------------------------------------------- 1 | const prompt = require('prompt-sync')(); 2 | 3 | const num = parseInt(prompt("Enter your number here ")); 4 | const time = parseInt(prompt("Enter the times of multiplication ")); 5 | 6 | function multiplication(num, time){ 7 | 8 | if(time === 0){ 9 | return; 10 | } 11 | multiplication(num, time - 1); 12 | return console.log(`the multiplication of ${num} * ${time} is ${num * time}`); 13 | 14 | } 15 | 16 | multiplication(num, time); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day18_4July/returnSort.js: -------------------------------------------------------------------------------- 1 | // Write a program to sort a given data using recursive approach 2 | 3 | const array1 = [1, 8, 2, 4, 45, 5]; 4 | 5 | function sorting(array) { 6 | length = array.length - 1; 7 | for (let i = 0; i <= length; i++) { 8 | for (let j = 0; j <= length; j++) { 9 | if(array[j] > 9){ 10 | 11 | } 12 | if (array[j] < array[j - 1]) { 13 | let temp = array[j]; 14 | array[j] = array[j - 1] 15 | array[j - 1] = temp; 16 | 17 | 18 | } 19 | 20 | } 21 | } 22 | return array; 23 | } 24 | console.log(sorting(array1)); 25 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day18_4July/smallest.js: -------------------------------------------------------------------------------- 1 | // create a program thats find smallest number without using comparssion operator 2 | 3 | a = 25; 4 | b = 12; 5 | c = 8; 6 | 7 | for(let i = a; i >= 0; i-- ){ 8 | 9 | a -= 1; 10 | b -= 1; 11 | c -= 1; 12 | 13 | if(a === 0){ 14 | i = a; 15 | console.log('A'); 16 | } else if(b === 0){ 17 | console.log('B'); 18 | i = b; 19 | } else if(c === 0){ 20 | i = c; 21 | console.log('C'); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day19_5July/anagram.js: -------------------------------------------------------------------------------- 1 | let anagram = (s1, s2) => { 2 | if (s1.length != s2.length) { 3 | return false; 4 | } 5 | 6 | let count = {} 7 | for (let i of s1) { 8 | count[i] = (count[i] || 0) + 1; 9 | } 10 | 11 | for (let j of s2) { 12 | if (!count[j]) { 13 | return false; 14 | } 15 | count[j] -= 1. 16 | } 17 | return true; 18 | } 19 | 20 | console.log(anagram('bunty', 'nubyt')) -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day21_13July/bracket.js: -------------------------------------------------------------------------------- 1 | function bracket(n,open,close,str) { 2 | if(open === n && close === n){ 3 | console.log(str); 4 | return; 5 | } 6 | if(open < n){ 7 | bracket(n, open+1, close, str+"(") 8 | } 9 | if(open > close) { 10 | bracket(n, open, close+1, str+")") 11 | } 12 | } 13 | 14 | bracket(3,0,0,""); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day21_13July/sum.js: -------------------------------------------------------------------------------- 1 | function sum (num1, num2) { 2 | while(num2 != 0) { 3 | let carry = num1 & num2 4 | num1 = num1 ^ num2; 5 | 6 | num2 = carry << 1; 7 | } 8 | return num1; 9 | 10 | } 11 | 12 | console.log(sum(3,5)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day21_13July/sumOfSubarray.js: -------------------------------------------------------------------------------- 1 | let array = [2, 3, 40, 5, 6, 7, 8]; 2 | 3 | function max(array) { 4 | let sum = 0; 5 | let max_Sum = 0; 6 | 7 | for (let i = 0; i < array.length - 1; i++) { 8 | sum = array[i] + array[i + 1] 9 | max_Sum = Math.max(sum, max_Sum); 10 | } 11 | return max_Sum; 12 | } 13 | 14 | 15 | console.log(max(array)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/accessing_an_array.js: -------------------------------------------------------------------------------- 1 | // creatin an array using new keyword 2 | const array = new Array(4); 3 | 4 | array[0] = 1; 5 | array[1] = 2; 6 | array[2] = 3; 7 | array[4] = 4; 8 | 9 | // printing array; 10 | console.log(array); 11 | 12 | 13 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/array.js: -------------------------------------------------------------------------------- 1 | const arr = new Array(4); 2 | 3 | arr[0] = "aman"; 4 | arr[1] = "Banti Kumar"; 5 | arr[10] = "Pammy Burnwal"; 6 | arr[3] = "Rohit"; 7 | console.log(arr[4]); 8 | console.log(arr); 9 | console.log(arr.length); 10 | console.log(arr[4] = "Appple"); 11 | console.log(arr[4]); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/day22_14July/addingSubArray.js: -------------------------------------------------------------------------------- 1 | 2 | let array = [1,2, 3, 4, 5, 6,7, 8 , 9]; 3 | 4 | let two = 4; 5 | 6 | // sumOfSubArray(array, two); 7 | 8 | 9 | function sumOfSubArray(array, elementsnum){ 10 | // index = elementsnum - 1; 11 | let sum = 0; 12 | for(let i = 0; i < elementsnum; i++){ 13 | sum += array[i]; 14 | } 15 | 16 | for(let i = elementsnum - 1; i < array.length; i++){ 17 | console.log(sum); 18 | sum = sum + array[i + 1] - array[i - 2]; 19 | 20 | } 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/day22_14July/dublicateElement.js: -------------------------------------------------------------------------------- 1 | array = [1,2, 6, 3, 4, 7, 1]; 2 | 3 | function isDublicateElemet(array) { 4 | for(let i = 0; i < array.length - 1; i++) { 5 | for(let j = i + 1; j < array.length; j++){ 6 | if(array[i] === array[j]) { 7 | return true; 8 | } 9 | } 10 | } 11 | return false; 12 | } 13 | 14 | let result = isDublicateElemet(array); 15 | 16 | console.log(result); 17 | 18 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/day22_14July/isprime.js: -------------------------------------------------------------------------------- 1 | function isPrime(num) { 2 | if(num === 1 || num === 0) { 3 | return false; 4 | } 5 | 6 | for(let i = 2; i < num; i++) { 7 | if(num % i === 0) { 8 | return false; 9 | } 10 | } 11 | 12 | return true; 13 | 14 | 15 | } 16 | 17 | function sumOfPrime(num) { 18 | for(let i = 2; i <= Math.floor(num / 2); i++) { 19 | if(isPrime(i) === true && isPrime(num - i) === true) { 20 | console.log(i, num - i) 21 | return; 22 | } 23 | } 24 | return console.log("Not found"); 25 | 26 | } 27 | 28 | sumOfPrime(11); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/day22_14July/subarray.js: -------------------------------------------------------------------------------- 1 | function subarray(array) { 2 | let length = array.length; 3 | 4 | for(j = 0; j < length; j++) { 5 | let temp = []; 6 | for(k = j; k < length; k++) { 7 | 8 | temp.push(array[k]); 9 | console.log(temp); 10 | } 11 | } 12 | 13 | return; 14 | } 15 | 16 | let array = [1,2, 3, 4, 5, 6]; 17 | subarray(array); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/day23_15July/selection_Sorting.js: -------------------------------------------------------------------------------- 1 | function se(arr) { 2 | let min; 3 | for (let i = 0; i < arr.length - 1; i++) { 4 | min = i; 5 | for (let j = i + 1; j < arr.length; j++) { 6 | if (arr[j] < arr[min]) { 7 | min = j; 8 | } 9 | } 10 | let temp = arr[i]; 11 | arr[i] = arr[min]; 12 | arr[min] = temp; 13 | } 14 | return arr; 15 | } 16 | 17 | let arr = [3, 6, 1, 4, 0, 2]; 18 | let arr2 = [101,86,1001,2,8,26]; 19 | 20 | console.log(se(arr)); 21 | console.log(se(arr2)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/day23_15July/subArray.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let subArray = (a) => { 4 | for (let l = 0; l < a.length; l++) { 5 | let mj = [] 6 | for (let i = l; i < a.length; i++) { 7 | mj.push(a[i]) 8 | console.log(mj) 9 | } 10 | } 11 | } 12 | let a = [5, 4, 3, 2, 1] 13 | subArray(a); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/forEach.js: -------------------------------------------------------------------------------- 1 | 2 | const numbers = ['a', 'b', 'c', 'd']; 3 | 4 | 5 | 6 | numbers.forEach((elments, index ) => { 7 | console.log(index); 8 | console.log(elments); 9 | }) 10 | 11 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/forLoop.js: -------------------------------------------------------------------------------- 1 | const arr = [1,2,3, 4]; 2 | 3 | for(let i = 0; i < arr.length; i++){ 4 | console.log(arr[i]); 5 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/functionExpression.js: -------------------------------------------------------------------------------- 1 | const array = [1, 34, 4, 5, 32, 42, 322]; 2 | 3 | 4 | 5 | let printingArray = function(elemnts, index) { 6 | console.log(index); 7 | console.log(elemnts); 8 | } 9 | 10 | array.forEach(printingArray); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day24_18July/primeornot.js: -------------------------------------------------------------------------------- 1 | for (let i = 2; i <= 200; i++) { 2 | a = true; 3 | for (let j = 2; j < i; j++) { 4 | if (i % j === 0) { 5 | a = false; 6 | break; 7 | } 8 | } 9 | a === true ? console.log(i, " is prime") : console.log(i, " is not prime"); 10 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day25_19July/anagram.js: -------------------------------------------------------------------------------- 1 | let anagram = (s1, s2) => { 2 | if (s1.length != s2.length) { 3 | return false; 4 | } 5 | 6 | let count = {} 7 | for (let i of s1) { 8 | count[i] = (count[i] || 0) + 1; 9 | } 10 | 11 | for (let j of s2) { 12 | if (!count[j]) { 13 | return false; 14 | } 15 | count[j] -= 1. 16 | } 17 | return true; 18 | } 19 | 20 | console.log(anagram('bunty', 'nubyt')) -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day26_20July.js/inversion.js: -------------------------------------------------------------------------------- 1 | /** 2 | * conditions : - 3 | * 1. i < j 4 | * 2. only 2 elements from an array 5 | */ 6 | 7 | function inversion(arr) { 8 | let totalinversion = 0; 9 | 10 | for(let i = 0; i < arr.length; i++){ 11 | for(let j = i + 1; j < arr.length; j++) { 12 | if(arr[i] > arr[j]) { 13 | totalinversion++; 14 | // console.log(arr[i], " ", arr[j], " ", totalinversion) 15 | } 16 | } 17 | } 18 | return totalinversion; 19 | } 20 | 21 | 22 | const arr = [8, 5, 4, 2, 1]; 23 | 24 | console.log(inversion(arr)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day27_21July/test_result.js: -------------------------------------------------------------------------------- 1 | // not completed 2 | 3 | function resutlt(total_Num, scored_Marks, total_questions, obtained_questions) { 4 | let avgMarks = total_Num / total_questions; 5 | n = 1; 6 | let negativenum = -(n * 4); 7 | i = 0; 8 | while(i != scored_Marks ) { 9 | 10 | } 11 | 12 | } 13 | 14 | total_Num = 200; 15 | scored_Marks = 38; 16 | total_questions = 30; 17 | obtained_questions = 28; 18 | 19 | 20 | console.log(parseFloat(total_Num / total_questions)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day28_22July.js/bubblesort.js: -------------------------------------------------------------------------------- 1 | function bubbleSort(array) { 2 | for(let i = 0; i < array.length - 1 ; i++) { 3 | let isSwaped = false; 4 | 5 | for(let j = 0; j < array.length - i - 1; j++) { 6 | if(array[j] > array[j + 1]) { 7 | temp = array[j]; 8 | array[j] = array[j + 1]; 9 | array[j + 1] = temp; 10 | 11 | isSwaped = true; 12 | } 13 | } 14 | 15 | if(isSwaped != true){ 16 | break; 17 | } 18 | } 19 | 20 | return array; 21 | } 22 | 23 | let arr = [2, 5, 1, 8, 0, 1]; 24 | 25 | console.log(bubbleSort(arr)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day28_22July.js/insertionSort.js: -------------------------------------------------------------------------------- 1 | function insertionSort(arr) { 2 | //Assume that arr[0] is sorted, which means we will have to sort 3 | //elements from 1..arr.length - 1 4 | let firstElementUnsortedPart, j; 5 | 6 | for (let i = 1; i < arr.length; i++) { 7 | firstElementUnsortedPart = arr[i]; 8 | //Sorted part will be from 0 to i - 1 9 | j = i - 1; 10 | 11 | while (j >= 0 && arr[j] > firstElementUnsortedPart) { 12 | arr[j + 1] = arr[j]; 13 | j = j - 1; 14 | } 15 | arr[j + 1] = firstElementUnsortedPart; 16 | } 17 | return arr; 18 | } 19 | 20 | let arr = [5, 4, 3, 2, 0, 7, 6] 21 | console.log(insertionSort(arr)) 22 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day28_22July.js/pivot.js: -------------------------------------------------------------------------------- 1 | function partion(arr, l, r,) { 2 | let i = l - 1; 3 | let pivot = arr[r] 4 | for(let j = 0; j <= r - 1; j ++) { 5 | if(arr[j] < pivot) { 6 | i++; 7 | let temp = arr[i]; 8 | arr[i] = arr[j]; 9 | arr[j] = temp; 10 | } 11 | 12 | 13 | } 14 | let temp = arr[i + 1]; 15 | arr[i + 1] = arr[r]; 16 | arr[r] = temp; 17 | return i + 1; 18 | } 19 | const arr = [1, 5, 3, 6,3, 4]; 20 | // let arr = [1, 5, 2, 6, 2, 9, 7]; 21 | console.log(arr); 22 | 23 | console.log(partion(arr, 0, arr.length - 1)); 24 | 25 | console.log(arr); 26 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day28_22July.js/quickSortAlgo.js: -------------------------------------------------------------------------------- 1 | function merging(arr,l, r) { 2 | let i = l - 1; 3 | let pivot = arr[r] 4 | for(let j = 0; j <= r - 1; j ++) { 5 | if(arr[j] < pivot) { 6 | i++; 7 | let temp = arr[i]; 8 | arr[i] = arr[j]; 9 | arr[j] = temp; 10 | } 11 | 12 | 13 | } 14 | let temp = arr[i + 1]; 15 | arr[i + 1] = arr[r]; 16 | arr[r] = temp; 17 | return i + 1; 18 | 19 | } 20 | 21 | const arr = [1, 5, 3,6,3, 4]; 22 | // let arr = [1, 5, 2, 6, 2, 9, 7]; 23 | 24 | 25 | merging(arr, 0, arr.length - 1); 26 | console.log(arr); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day28_22July.js/selectionSort.js: -------------------------------------------------------------------------------- 1 | function selectionSort(arr) { 2 | let miniIndex; 3 | 4 | for(let i = 0; i < arr.length - 2; i++ ) { 5 | miniIndex = i; 6 | 7 | for(let j = i + 1; j < arr.length - 1; j++) { 8 | if(arr[j] < arr[miniIndex]) { 9 | miniIndex = j; 10 | } 11 | } 12 | 13 | let temp = arr[i]; 14 | arr[i] = arr[miniIndex]; 15 | arr[miniIndex] = temp 16 | } 17 | return arr; 18 | } 19 | 20 | 21 | let arr = [3, 6, 1, 4, 0, 5, 6, 9] 22 | console.log(selectionSort(arr)) 23 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day29_24July/ArrayMultiplication.js: -------------------------------------------------------------------------------- 1 | let arr = [1, 3,- 4, 4 , -3, 5, -19, 13, 19] 2 | //[1, 3, 19, 4, 13, 5, -19 -3 -4]; 3 | 4 | 5 | function arrangement(array) { 6 | 7 | let length = array.length - 1; 8 | 9 | for(let i = 0; i < array.length; i++) { 10 | 11 | if(i === length) { 12 | break; 13 | } 14 | 15 | if(array[i] > 0) { 16 | continue; 17 | } 18 | 19 | let temp = array[i] 20 | array[i] = array[length]; 21 | array[length] = temp; 22 | 23 | length--; 24 | 25 | } 26 | 27 | return array; 28 | } 29 | 30 | console.log(arrangement(arr)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day29_24July/even_odd_array.js: -------------------------------------------------------------------------------- 1 | // Rearrange an array such that even positioned elements are greater than odd positioned elements 2 | 3 | 4 | // class EvenOddArrangment { 5 | // constructor(array, length) { 6 | // this.array = array; 7 | // this.length = length; 8 | // } 9 | 10 | 11 | // arranging(array, length) { 12 | // // array.sort(); 13 | // arr = array(a, b => a > b ) 14 | // return array; 15 | 16 | // } 17 | // } 18 | 19 | // let a = new EvenOddArrangment; 20 | 21 | // console.log(a.arranging(arr)) 22 | 23 | 24 | let arr = [1, 3, 6, 12, 53, 6, 3]; 25 | // [1, 3, 3, 6, 6, 12, 53] 26 | arr.sort(function(a, b){return a-b}); 27 | 28 | console.log(arr); 29 | 30 | 31 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day29_24July/quickSort.js: -------------------------------------------------------------------------------- 1 | // error 2 | const arr = [1, 3, 23, 2, 8, 9, 12]; 3 | 4 | console.log(partion(arr, 0, arr.length - 1)); 5 | 6 | function partion(arr, l, r) { 7 | 8 | let random = Math.floor(Math.random() * (r - l) + l); 9 | 10 | let pivit = random; 11 | 12 | random = arr[r]; 13 | 14 | arr[r] = pivit; 15 | 16 | let i = l - 1; 17 | 18 | for(j = l; j <= r - 1; j++) { 19 | if(arr[j] < pivit) { 20 | i++ 21 | let temp = arr[j]; 22 | arr[j] = arr[i]; 23 | arr[i] = temp; 24 | } 25 | 26 | } 27 | 28 | let temp = arr[i + i]; 29 | arr[i + 1] = arr[r]; 30 | arr[r] = temp; 31 | 32 | return(arr); 33 | 34 | 35 | 36 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day30_28July/moving array element.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 2 | 3 | console.log(moving(arr, 3)); 4 | 5 | function moving(arr, n) { 6 | 7 | let arr2 = new Array() 8 | for(let i = arr.length - n; i < arr.length; i++) { 9 | let num = arr[i]; 10 | arr2.push(num); 11 | } 12 | 13 | for (let i = 0; i < arr.length - n; i++) { 14 | let num = arr[i]; 15 | arr2.push(num); 16 | } 17 | 18 | return arr2; 19 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day31_29July/check square.js: -------------------------------------------------------------------------------- 1 | // console.log(PerfectSquare(4)); 2 | 3 | let PerfectSquare = (n) => { 4 | let check; 5 | for (let i = 1; i < n; i++) { 6 | if (i * i === n) { 7 | check = true; 8 | break; 9 | } 10 | 11 | else { 12 | check = false; 13 | } 14 | 15 | } 16 | return check; 17 | } 18 | 19 | 20 | let result = PerfectSquare (5); 21 | 22 | console.log(result); 23 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day32_30July/hash map.js: -------------------------------------------------------------------------------- 1 | let countMap = new Map(); 2 | 3 | //Set and Get : two functions/operations on a Map 4 | //Set -> set (key, value) in the map 5 | //Get -> get value for a given key 6 | 7 | countMap.set('a', 2); 8 | countMap.set('b', 6); 9 | countMap.set('c', 7); 10 | countMap.set('a', 9); 11 | 12 | console.log(countMap.get('c')) 13 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day32_30July/transpose of a matrix.js: -------------------------------------------------------------------------------- 1 | const matrix = [ 2 | [1, 2, 3, 4], 3 | [5, 6, 7, 8], 4 | [9, 10, 11, 12], 5 | [13, 14, 15, 16] 6 | ] 7 | 8 | console.log(transpose(matrix)); 9 | 10 | function transpose(matrix) { 11 | 12 | // crating a new array 13 | let tMatrix = new Array(matrix.length); 14 | 15 | for(let i = 0; i < matrix.length; i++){ 16 | // crating two D array 17 | tMatrix[i] = new Array(matrix[0].length - 1); 18 | } 19 | 20 | 21 | for(let i = 0; i < tMatrix.length; i++) { 22 | for (let j = 0; j < tMatrix[0].length; j++) { 23 | tMatrix[i][j] = matrix[j][i] 24 | } 25 | } 26 | 27 | return tMatrix; 28 | } 29 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day32_30July/transpose of matrix in place algorithm.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function transpose(matrix) { 4 | 5 | for(let i = 0; i < matrix.length; i++) { 6 | 7 | for (let j = i + 1; j < matrix[0].length; j++) { 8 | 9 | let temp = matrix[i][j]; 10 | 11 | matrix[i][j] = matrix[j][i]; 12 | 13 | matrix[j][i] = temp; 14 | 15 | } 16 | 17 | } 18 | 19 | return matrix; 20 | } 21 | 22 | const matrix = [ 23 | [1, 2, 3, 4], 24 | [5, 6, 7, 8], 25 | [9, 10, 11, 12], 26 | [13, 14, 15, 16] 27 | ] 28 | 29 | 30 | 31 | console.log(transpose(matrix)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day33_31July/data reference.js: -------------------------------------------------------------------------------- 1 | a; 2 | 3 | // b = a + 1; 4 | 5 | // console.log(a); // 5 6 | 7 | 8 | function a (a) { 9 | 10 | return console.log("Aman"); 11 | } 12 | 13 | // console.log(a(4)); 14 | 15 | console.log(typeof(a)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day33_31July/quick sort.js: -------------------------------------------------------------------------------- 1 | function partition(a, l, r) { 2 | let pivot = a[r] 3 | 4 | let i = l - 1; 5 | 6 | for (let j = l; j <= r - 1; j++) { 7 | if (a[j] < pivot) { 8 | i++; 9 | let mj = a[j] 10 | a[j] = a[i] 11 | a[i] = mj; 12 | } 13 | } 14 | 15 | let virus = a[i + 1] 16 | a[i + 1] = a[r] 17 | a[r] = virus; 18 | 19 | return i + 1; 20 | } 21 | 22 | function name1(a, l, r) { 23 | if (l < r) { 24 | let pi = partition(a, l, r) 25 | name1(a, l, pi - 1) 26 | name1(a, pi + 1, r) 27 | return a; 28 | } 29 | } 30 | 31 | 32 | 33 | 34 | let a = [5, 1, 3, 7, 8, 9, 10, 2, 4] 35 | console.log(name1(a, 0, a.length - 1)) -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/july/day33_31July/scope.js: -------------------------------------------------------------------------------- 1 | function nameis() { 2 | let name1 = "Aman"; 3 | function callling() { 4 | console.log(name1); 5 | } 6 | 7 | callling(); 8 | 9 | } 10 | 11 | 12 | nameis(); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day11_1_6th_june/assignment1.js: -------------------------------------------------------------------------------- 1 | // Requirements: "Given a positive integer A, find a pair of integers a, b such that 2 | // a and b are positive 3 | // A <= B 4 | // a^2 + b^2 = A 5 | // 0<=A<=100000 6 | 7 | function squareSum(num) { 8 | var a = 0; 9 | while (a * a < num) { 10 | var b = 0; 11 | while (b * b < num) { 12 | if (a * a + b * b == num) { 13 | if (a <= b) { 14 | console.log(a + "," + b); 15 | } 16 | } 17 | b += 1; 18 | } 19 | a += 1; 20 | 21 | } 22 | } 23 | 24 | 25 | 26 | squareSum(50); 27 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day12_1_19nth_june/map_in_javascript.js: -------------------------------------------------------------------------------- 1 | let newMap = new Map; 2 | // new is a key word and Map is a -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day12_1_19nth_june/unique_number_in_array.js: -------------------------------------------------------------------------------- 1 | let array = [3, 2, 42, 42, 3, 5, 6, 6]; 2 | 3 | let countMap = new Map(); 4 | 5 | // console.log(countMap); 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day12_20June/alphabate.js: -------------------------------------------------------------------------------- 1 | let a = "Example " 2 | 3 | // console.log(a) 4 | 5 | for(let i = a.length - 1; i >= 0; i--){ 6 | if(a[i] >= 'a' && a[i] <= 'z' || a[i] >='A' && a[i] <= 'Z'){ 7 | console.log(a[i]) 8 | break; 9 | } 10 | } 11 | 12 | 13 | // let str = " Example4 " 14 | 15 | // let lastchar; 16 | // for(let i = str.length - 1; i >= 0; i--){ 17 | // if(str[i] != ' '){ 18 | // lastchar = str[i]; 19 | // break; 20 | // } 21 | 22 | // } 23 | 24 | // // console.log(lastchar) -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day12_20June/input.js: -------------------------------------------------------------------------------- 1 | const readline = require("readline"); 2 | 3 | const rl = readline.createInterface({ 4 | input: process.stdin, 5 | output: process.stdout, 6 | }); 7 | 8 | rl.question("What is your name? ", function (answer) { 9 | console.log(`oh, so your name is ${answer}`); 10 | console.log("Closing the interface"); 11 | rl.close(); 12 | }); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day12_20June/script.js: -------------------------------------------------------------------------------- 1 | let array = [3,3, 5, 6] 2 | 3 | let array2 = array; 4 | 5 | console.log(array2); 6 | 7 | array2.push(4); 8 | console.log(array2); 9 | 10 | console.log(array); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day12_20June/swati.js: -------------------------------------------------------------------------------- 1 | let array = [1, 4, 2, 3]; 2 | 3 | // function secondHighestNumber(arr){ 4 | // let num = Math.max(...arr); 5 | // arr.splice(arr.indexOf(num),1); 6 | // num = Math.max(...arr); 7 | // return num; 8 | // } 9 | 10 | // console.log(secondHighestNumber(array)); 11 | 12 | 13 | 14 | 15 | 16 | function secondHighestNumber(arr) { 17 | let max = arr[0]; 18 | let secondMax = arr[0]; 19 | let temp; 20 | 21 | for (let i = 0; i <= arr.length - 1; i++) { 22 | if (max < arr[i]) { 23 | max = arr[i]; 24 | } 25 | } 26 | return max; 27 | } 28 | 29 | console.log(secondHighestNumber(array)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day13_25June/fabonic.js: -------------------------------------------------------------------------------- 1 | function fabonaci(num){ 2 | 3 | if(num === 0 || num === 1){ 4 | return num; 5 | } 6 | 7 | 8 | return fabonaci(num - 1) + fabonaci(num - 2); 9 | 10 | 11 | } 12 | 13 | 14 | console.log(fabonaci(10)); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day13_25June/factorial.js: -------------------------------------------------------------------------------- 1 | // var temp = 1; 2 | // function factoril(num){ 3 | 4 | // for(let i = 1; i <= num; i++){ 5 | // temp = temp * i; 6 | 7 | // } 8 | // console.log(temp) 9 | // } 10 | 11 | // factoril(4); 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | function factoril(num){ 24 | if(num == 1){ 25 | return 1; 26 | } 27 | 28 | return num* factoril(num - 1); 29 | } 30 | 31 | console.log(factoril(4)) 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day13_25June/forEach.js: -------------------------------------------------------------------------------- 1 | let array = ["Aman", "Burnwal", "Hello", "How", "Are", "you"]; 2 | 3 | //First way of using forEach 4 | //Arrow function 5 | /* 6 | (element, index) => { 7 | console.log(element); 8 | console.log(index); 9 | } 10 | 11 | function printElements(element, index){ 12 | console.log(element); 13 | console.log(index); 14 | } 15 | */ 16 | 17 | (element, index) => { 18 | console.log(element); 19 | console.log(index); 20 | } 21 | 22 | function printElements(element, index){ 23 | console.log(element); 24 | console.log(index); 25 | } 26 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day13_25June/increasementOderNumber.js: -------------------------------------------------------------------------------- 1 | function incre(num){ 2 | if(num === 1){ 3 | console.log(1) 4 | return; 5 | } 6 | 7 | incre(num - 1); 8 | console.log(num); 9 | 10 | 11 | } 12 | 13 | incre(10); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day13_25June/temp.js: -------------------------------------------------------------------------------- 1 | let num = 10 2 | let a = 0, b = 1, c; 3 | 4 | for (let i = 0 ; i <= num; i++) 5 | { 6 | console.log("Your a is " +a) 7 | console.log("Your b is " +b) 8 | console.log("Your c is " +c) 9 | 10 | console.log("next loop \n \n") 11 | c = a + b; 12 | a = b; 13 | b = c; 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/codeplito.js: -------------------------------------------------------------------------------- 1 | // create a function that takes a string and returns the number of vowels in the string 2 | 3 | function countVowels(str) { 4 | var vowels = ['a', 'e', 'i', 'o', 'u']; 5 | var count = 0; 6 | for (var i = 0; i < str.length; i++) { 7 | if (vowels.includes(str[i])) { 8 | count++; 9 | } 10 | } 11 | return count; 12 | } 13 | 14 | 15 | 16 | console.log(countVowels('hello')); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/debug.js: -------------------------------------------------------------------------------- 1 | function palindrome(a) { 2 | let b = a.toUpperCase(); 3 | for (let i = b.length; i >= 0; i--) { 4 | // console.log(b[i]); 5 | 6 | if (b[i] != b[b.length - i - 1]) { 7 | c = "its not palindrome"; 8 | break; 9 | } 10 | else { 11 | c = "its a palindrome"; 12 | } 13 | 14 | } 15 | console.log(c); 16 | } 17 | 18 | palindrome("abcba"); 19 | 20 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/freeze.js: -------------------------------------------------------------------------------- 1 | function calculateDaysBetweenDates(begin, end) { 2 | var date1 = new Date(begin); 3 | var date2 = new Date(end); 4 | var timeDiff = Math.abs(date2.getTime() - date1.getTime()); 5 | var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 6 | return diffDays; 7 | } 8 | 9 | console.log(calculateDaysBetweenDates('12/11/2000', '06/26/2022')); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/palindrome.js: -------------------------------------------------------------------------------- 1 | function palindrome(myString){ 2 | 3 | 4 | 5 | /* Check to see if myString is a Palindrome*/ 6 | var isPalindrome = true; 7 | var stringLength = myString.length; 8 | var midPoint = Math.floor(stringLength/2); 9 | 10 | for(var i = 0; i < midPoint; i++){ 11 | if(myString[i] != myString[stringLength - i - 1]){ 12 | isPalindrome = false; 13 | break; 14 | } 15 | } 16 | 17 | if(isPalindrome){ 18 | console.log("The string " + myString + " is a Palindrome"); 19 | } 20 | else{ 21 | console.log("The string " + myString + " is not a Palindrome"); 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | palindrome('madam') -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/palindrone.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/Practice In JavaScript Progrmas/june/day14_26June/palindrone.zip -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | calculateDaysBetweenDates('12/11/2000', '06/26/2022')); -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/Practice In JavaScript Progrmas/june/day14_26June/test.js -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day14_26June/test2.js: -------------------------------------------------------------------------------- 1 | let n = parseInt(readline()); 2 | let arr = []; 3 | arr = readline().split(" "); 4 | console.log(countOddNumbers(arr, n)); 5 | 6 | function countOddNumbers(arr, n) { 7 | // write your logic here 8 | let count = 0; 9 | for (let i = 0; i < n; i++) { 10 | if (arr[i] % 2 != 0) { 11 | count++; 12 | } 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day15_27June/composability.js: -------------------------------------------------------------------------------- 1 | const add = (a, b) => a + b; 2 | const minus = (a, b) => a - b; 3 | const mul = (a, b) => a * b; 4 | 5 | const result = mul(2, add(4, minus(4, 2))) 6 | console.log(result); 7 | -------------------------------------------------------------------------------- /Practice In JavaScript Progrmas/june/day15_27June/higherOrder.js: -------------------------------------------------------------------------------- 1 | // filter program example 2 | 3 | let array = [2, 3, 4, 4, 22, 2] 4 | 5 | // console.log(array);e 6 | 7 | const filterArray = array.filter(function(item){ 8 | return item > 3 9 | }) 10 | 11 | arr = [1, 3, 4, 5, 5, 6, 7] 12 | 13 | console.log(filterArray); 14 | 15 | // console.log(array) 16 | 17 | 18 | array.sort(function(a,b){ 19 | return a - b 20 | }) 21 | 22 | console.log(array); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # javascrpit 3 | 4 | hey this repo is fully made for javascript problem solving. 5 | if you get any bug or error kindly inform me 6 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/04 Nov Binary Search/find the number.js: -------------------------------------------------------------------------------- 1 | function getSum(sum) { 2 | let result = 0; 3 | 4 | while (sum > 0) { 5 | result += sum 6 | sum = Math.floor(sum / 10) 7 | } 8 | return result; 9 | } 10 | 11 | function findNum(n) { 12 | let beg = 1; end = n 13 | 14 | while (beg <= end) { 15 | 16 | let mid = Math.floor(beg + (end - beg) / 2); 17 | 18 | let f = getSum(mid) 19 | 20 | if (f === n) return mid; 21 | 22 | f > n ? end = mid - 1 : beg = mid + 1; 23 | } 24 | return -1; 25 | } 26 | 27 | 28 | 29 | console.log(findNum(116)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/04 Nov Binary Search/find x sum.js: -------------------------------------------------------------------------------- 1 | let num = 124523; 2 | 3 | function sum(num) { 4 | 5 | let result = 0; 6 | 7 | while (num > 0) { 8 | 9 | result += num ; 10 | num = Math.floor(num / 10); 11 | 12 | } 13 | return result; 14 | } 15 | 16 | console.log(sum(num)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/10 Oct Array and Object/Arrays_and_Objects_Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/Advance DSA/10 Oct Array and Object/Arrays_and_Objects_Notes.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/10 dec BT/Breadth first search.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @Breadth @first @search -> start from the root node & 3 | * visits all the nodes of the current level before moving to the next level. 4 | * 5 | * it is also known as level order traversal 6 | */ -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/Assignment/Assignment 2.js: -------------------------------------------------------------------------------- 1 | // 2. Write a program to rearrange the elements such like positive numbers shift to the end and negative 2 | // numbers to the start. 3 | 4 | function rearrange(arr, left, right) { 5 | 6 | while (left!== right) { 7 | if (arr[left] >= 0 && arr[right] < 0) { 8 | 9 | [arr[left], arr[right]] = [arr[right], arr[left]] 10 | } else if (arr[left] < 0) { 11 | left++; 12 | } else if (arr[right] >= 0) { 13 | right--; 14 | } 15 | } 16 | return arr; 17 | } 18 | 19 | 20 | const arr = [- 5, 3, -4, 88, -9, -10, 21, 5, 6]; 21 | 22 | rearrange(arr, 0, arr.length - 1); 23 | 24 | console.log(arr); -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/Problem_Solving_On_Arrays_and_Objects.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/Problem_Solving_On_Arrays_and_Objects.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/class desk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/class desk.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/self practice/anagram with in built function: -------------------------------------------------------------------------------- 1 | function Anagram(s1, s2) { 2 | let str1 = s1.toLowerCase().split("").sort().join(""); 3 | let str2 = s2.toLowerCase().split("").sort().join(""); 4 | 5 | console.log(str1, str2) 6 | return str1 === str2 7 | } 8 | 9 | let s1 = "Care"; 10 | let s2 = "erac"; 11 | console.log(Anagram(s1, s2)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/11 Oct Advanced Problem Solving Arrays and Objects/self practice/anagram.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function anagram(s, t) { 4 | 5 | if (s.length !== t.length) return false; 6 | 7 | let store = {}; 8 | 9 | for (let i = 0; i < s.length; i++) { 10 | if (store[s[i]] > 0) { 11 | store[s[i]] += 1; 12 | } else { 13 | store[s[i]] = 1; 14 | } 15 | } 16 | 17 | for (let j = 0; j < t.length; j++) { 18 | if (store[s[j]] > 0) { 19 | store[s[j]] -= 1; 20 | } 21 | 22 | if (store[s[j]] < 0) { 23 | return false; 24 | } 25 | } 26 | return true; 27 | } 28 | 29 | console.log(anagram("aman", "mana")) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/14 Nov linked list/linked list.js: -------------------------------------------------------------------------------- 1 | class Node{ 2 | constructor(x) { 3 | this.data = x; 4 | this.next = null; 5 | } 6 | } 7 | 8 | 9 | class LinkedList { 10 | 11 | constructor() { 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/25 Nov stack/immediateSmallerElement.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} arr 3 | * @param {number} n 4 | */ 5 | 6 | class Solution { 7 | immediateSmaller(arr, n) { 8 | //code here 9 | 10 | let stack = []; 11 | 12 | 13 | for (let i = 0; i < n - 1; i++) { 14 | 15 | arr[i] > arr[i + 1] ? arr[i] = arr[i + 1] : arr[i] = -1; 16 | } 17 | 18 | arr[n - 1] = -1; 19 | return; 20 | 21 | } 22 | 23 | } 24 | 25 | console.log(immediateSmaller( [4, 2, 1, 5, 3], 5)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/25 Nov stack/nextLargerElement.js: -------------------------------------------------------------------------------- 1 | // your code goes here 2 | 3 | function nextLargerElement(N, arr) { 4 | 5 | let stack = []; 6 | 7 | let ans = []; 8 | 9 | for (let i = N - 1; i >= 0; i--) { 10 | 11 | 12 | while (stack.length && stack[stack.length - 1] <= arr[i]) { 13 | stack.pop(); 14 | } 15 | 16 | stack.length === 0 ? ans[i] = -1 : ans[i] = stack[stack.length - 1]; 17 | 18 | stack.push(arr[i]) 19 | 20 | } 21 | console.log(ans) 22 | return ans 23 | } 24 | 25 | nextLargerElement(4, [1, 3, 2, 4]) 26 | 27 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/25 Nov stack/previous smallest element.js: -------------------------------------------------------------------------------- 1 | function immediateSmaller(arr, n) { 2 | //code here 3 | 4 | let stack = []; 5 | let ans = []; 6 | 7 | for (let i = 0; i < n; i++) { 8 | 9 | while (stack.length && stack[stack.length - 1] >= arr[i]) { 10 | stack.pop(); 11 | } 12 | 13 | stack.length === 0 ? ans[i] = -1 : ans[i] = stack[stack.length - 1]; 14 | 15 | stack.push(arr[i]) 16 | } 17 | return ans; 18 | 19 | } 20 | 21 | console.log(immediateSmaller([2, 3, 4, 5, 1], 5)); 22 | 23 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/25 Nov stack/temp.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @param {BigInt[]} arr 4 | * @param {number} n 5 | * @returns {BigInt[]} 6 | */ 7 | class Solution { 8 | //Function to find the next greater element for each element of the array. 9 | nextLargerElement(arr, n) { 10 | // code here 11 | 12 | let stack = []; 13 | let result = []; 14 | 15 | for (let i = n - 1; i >= 0; i--) { 16 | 17 | while (stack.length && stack[stack.length - 1] <= arr[i]) { 18 | stack.pop(); 19 | } 20 | 21 | result[i] = stack.length === 0 ? -1 : stack[stack.length - 1]; 22 | stack.push(arr[i]); 23 | } 24 | return result; 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/28 Oct BTS/First and Last position of an element in a sorted array.js: -------------------------------------------------------------------------------- 1 | // First and Last position of an element in a sorted array 2 | 3 | 4 | function findElement(arr, x) { 5 | let left = 0; 6 | let right = arr.length - 1; 7 | 8 | 9 | while (arr <= right) { 10 | 11 | 12 | 13 | } 14 | } 15 | 16 | const arr = [1, 2, 3, 3, 8, 9, 9, 10, 10, 10, 11]; -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/28 Oct BTS/binaray search.js: -------------------------------------------------------------------------------- 1 | function BinarySearch(arr, target) { 2 | 3 | let start = 0; 4 | let end = arr.length - 1; 5 | 6 | while (start <= end) { 7 | 8 | let mid = Math.ceil((start + end )/ 2); 9 | 10 | if (arr[mid] === target) return mid ; 11 | 12 | if (mid < target) { 13 | start = mid + 1 14 | } else { 15 | end = target - 1 16 | } 17 | } 18 | 19 | return -1 20 | } 21 | 22 | const arr = [1, 2, 3, 4, 5]; 23 | 24 | console.log(BinarySearch(arr, 5)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/28 Oct BTS/find repeating element using binary SEarch.js: -------------------------------------------------------------------------------- 1 | const arr = [0, 1, 2, 3, 4, 5, 5]; 2 | 3 | function repatedElement(arr) { 4 | 5 | let start = 0; 6 | let end = arr.length - 1; 7 | 8 | while (start <= end) { 9 | 10 | let mid = Math.ceil((end + start) / 2); 11 | 12 | // console.log(mid, arr[mid]) 13 | 14 | if (arr[mid] === arr[mid + 1] || arr[mid ] === arr[mid - 1]) return arr[mid]; 15 | 16 | if (arr[mid] >= mid) { 17 | start = mid + 1; 18 | 19 | 20 | } else { 21 | 22 | end = mid - 1; 23 | 24 | } 25 | } 26 | 27 | return -1; 28 | } 29 | 30 | 31 | console.log(repatedElement(arr)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/binaray search.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/Advance DSA/recursion revision/binaray search.js -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/bubble sort using recursion.js: -------------------------------------------------------------------------------- 1 | // bubble sort using recursion in asccending order 2 | 3 | function bubbleSort(arr, n) { 4 | 5 | if (n < 0) return; 6 | 7 | 8 | bubbleSort(arr, n - 1); 9 | 10 | arr[n] < arr[n - 1] ? [arr[n] , arr[n - 1]] = [arr[n - 1], arr[n]] : bubbleSort(arr, n - 1) 11 | } 12 | 13 | 14 | let arr = [1, 5, 2, 9, 7, 8, 11, 34, 56, 0]; 15 | bubbleSort(arr, arr.length); 16 | 17 | console.log(arr); 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/factorial.js: -------------------------------------------------------------------------------- 1 | // given a number n print all numbers in lexciographic order from 1 to n 2 | 3 | function factorial(n) { 4 | if (n === 1) return 1; 5 | 6 | return n * factorial (n - 1) 7 | } 8 | 9 | console.log(factorial(4)); 10 | 11 | 12 | function fibonachi(n) { 13 | 14 | if (n === 1) return 1; 15 | 16 | if (n === 0) return 0; 17 | 18 | return fibonachi(n - 1) + fibonachi(n - 2); 19 | } 20 | 21 | console.log(fibonachi(6)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/fibonachi.js: -------------------------------------------------------------------------------- 1 | 2 | let n = 6; 3 | 4 | function nthFibonachi(n) { 5 | if (n === 0) { 6 | return 0; 7 | } 8 | if (n === 1) { 9 | return 1; 10 | } 11 | 12 | 13 | return nthFibonachi(n - 1) + nthFibonachi(n - 2) 14 | } 15 | 16 | console.log(nthFibonachi(n)) 17 | 18 | // 0 1 1 2 3 5 8 13 21 19 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/find element index from array .js: -------------------------------------------------------------------------------- 1 | function indexForund(arr, len, x) { 2 | 3 | 4 | if (arr[len] === x) return len; 5 | 6 | 7 | return len < 0 ? -1 : indexForund(arr, len -= 1, x) 8 | } 9 | 10 | 11 | const arr = [1, 2, 3, 4, 34, 12] 12 | 13 | console.log(indexForund(arr, arr.length - 1, 4)) 14 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/isArraySorted.js: -------------------------------------------------------------------------------- 1 | 2 | // given an array of length n, check if the array is sorted or not using recursion 3 | 4 | function isArraySorted(arr, len) { 5 | 6 | if (len === 1) { 7 | return true; 8 | } 9 | 10 | 11 | 12 | isArraySorted(arr, len - 1) 13 | 14 | if (arr[len] > arr[len + 1]) { 15 | return false 16 | } 17 | 18 | return true; 19 | 20 | } 21 | 22 | const arr = [1, 2, 3,1, 4, 5]; 23 | const len = arr.length - 1; 24 | console.log(isArraySorted(arr, len)) 25 | 26 | 27 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/lexciOrder.js: -------------------------------------------------------------------------------- 1 | const a = []; 2 | 3 | function newARray(n, curr) { 4 | if (curr > n) return; 5 | 6 | console.log(curr) 7 | 8 | let i = 0; 9 | 10 | if (curr === 0) i = 1; 11 | newARray(n - 1); 12 | a.push(n); 13 | 14 | } 15 | 16 | 17 | 18 | function lexicoOrder(n, curr) { 19 | if (curr > n) { 20 | return; 21 | } 22 | console.log(curr); 23 | let i = 0; 24 | if (curr == 0) { 25 | i = 1; 26 | } 27 | for (; i <= 9; i++) { 28 | lexicoOrder(n, curr * 10 + i); 29 | } 30 | } 31 | 32 | lexicoOrder(20, 0); 33 | 34 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/lexo.js: -------------------------------------------------------------------------------- 1 | function lexo(i, n) { 2 | if (i <= n) { 3 | console.log(i); 4 | 5 | lexo(i * 10, n); 6 | if (i % 10 !== 9) { 7 | lexo(i + 1, n) 8 | } 9 | } 10 | } 11 | 12 | lexo(1, 1000) 13 | 14 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/merge two sorted array using recursion.js: -------------------------------------------------------------------------------- 1 | // merge two sorted array using recursion 2 | // 3 | 4 | function mergeTwoSortedArray(arr1, arr2, i, j) { 5 | 6 | if (i === arr1.length - 1) { 7 | return arr2; 8 | } 9 | 10 | if (j === arr2.length - 1) { 11 | return arr1; 12 | } 13 | 14 | if (arr1[i] <= arr2[j]) { 15 | return [arr1[i], ...mergeTwoSortedArray(arr1, arr2, i + 1, j)] 16 | } else { 17 | return [arr2[j], ...mergeTwoSortedArray(arr1, arr2, i, j + 1)] 18 | } 19 | 20 | 21 | } 22 | 23 | const arr1 = [1, 3, 5, 7, 9]; 24 | const arr2 = [2, 4, 6, 8, 10]; 25 | const i = 0; 26 | const j = 0; 27 | console.log(mergeTwoSortedArray(arr1, arr2, i, j)); 28 | 29 | // 30 | 31 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/monkey coin.js: -------------------------------------------------------------------------------- 1 | 2 | // consider a money system consisting of n coins. 3 | // Each coin has a positive integer value. 4 | // Your task is to calculate the number of distinct ordered ways you can produce a money sum x using the available coins. 5 | const coin = [1, 5, 7] 6 | total = 11; 7 | 8 | // using recursion 9 | function countWays(total, coin, n) { 10 | if (total == 0) { 11 | return 1; 12 | } 13 | if (total < 0) { 14 | return 0; 15 | } 16 | if (n <= 0 && total >= 1) { 17 | return 0; 18 | } 19 | return countWays(total, coin, n - 1) + countWays(total - coin[n - 1], coin, n) 20 | } 21 | 22 | 23 | console.log(countWays(total, coin, coin.length)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/n natural number in decreasing order.js: -------------------------------------------------------------------------------- 1 | function naturalNumber(n) { 2 | 3 | if (n === 1) { 4 | console.log(1); 5 | return; 6 | } 7 | 8 | console.log(n); 9 | 10 | naturalNumber(n - 1); 11 | } 12 | 13 | naturalNumber(5); -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/n natural numbers.js: -------------------------------------------------------------------------------- 1 | function natural(n) { 2 | 3 | if (n == 1) { 4 | console.log(n) 5 | return; 6 | } 7 | 8 | 9 | natural(n - 1); 10 | console.log(n) 11 | 12 | 13 | } 14 | 15 | (natural(5)); 16 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/pattern in reverse.js: -------------------------------------------------------------------------------- 1 | 2 | let ans = "" 3 | function pattern(n, col) { 4 | 5 | if (n === 0) return; 6 | 7 | if (col > n) { 8 | ans += "\n" 9 | col = 1 10 | pattern(n -= 1, col) 11 | } else { 12 | ans += "*" 13 | pattern(n, col+= 1) 14 | 15 | } 16 | 17 | 18 | } 19 | 20 | pattern(7, 1); 21 | 22 | console.log(ans) 23 | 24 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/pattern printing.js: -------------------------------------------------------------------------------- 1 | let ans = "" 2 | function printingStar(n, row, col) { 3 | 4 | // base case 5 | if (row > n) return; 6 | 7 | if (col > row) { 8 | ans += "\n" 9 | col = 1; 10 | printingStar(n, row += 1, col) 11 | 12 | } else { 13 | ans += "*" 14 | printingStar(n, row, col+= 1) 15 | } 16 | 17 | } 18 | 19 | printingStar(5, 1, 1); 20 | 21 | console.log(ans) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/possible subsequencel.js: -------------------------------------------------------------------------------- 1 | 2 | function possibleSubsequence(str, ans) { 3 | if (str.length == 0) { 4 | console.log(ans); 5 | return; 6 | } 7 | let ch = str[0]; 8 | let ros = str.slice(1); 9 | possibleSubsequence(ros, ans + ch); 10 | possibleSubsequence(ros, ans); 11 | } 12 | 13 | 14 | 15 | const arr = ['a', 'b', 'c']; 16 | 17 | console.log(possibleSubsequence(arr, "")) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/remove dublicates in String using.js: -------------------------------------------------------------------------------- 1 | let ans = ""; 2 | function withOutDuplicates(str, len) { 3 | if (len === str.length) { 4 | return ans; 5 | } 6 | 7 | if (str[len] !== str[len + 1]) { 8 | ans += str[len]; 9 | } 10 | 11 | 12 | withOutDuplicates(str, len += 1) 13 | 14 | } 15 | 16 | withOutDuplicates("helloolls", 0) 17 | 18 | console.log(ans) -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/star printing using recursion.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * start = 5 4 | * 5 | * * 6 | * * * 7 | * * * * 8 | * * * * * 9 | * * * * * * 10 | */ 11 | 12 | 13 | function printingStars(n, design, pattern) { 14 | 15 | if (n === 0) { 16 | 17 | console.log(design) 18 | return design; 19 | } 20 | 21 | console.log(design) 22 | 23 | printingStars(n - 1, design+= pattern, pattern); 24 | 25 | 26 | } 27 | 28 | // printingStars(12, "", "*") 29 | 30 | 31 | function printingStar(n, star) { 32 | 33 | if (n === 0) return console.log(star); 34 | 35 | console.log(star) 36 | 37 | printingStar(n - 1, star += "*") 38 | } 39 | 40 | // printingStar(5, "") -------------------------------------------------------------------------------- /ReLevel By Unacademy/Advance DSA/recursion revision/sumofDigits.js: -------------------------------------------------------------------------------- 1 | function sum(num) { 2 | if (num === 0) return 0; 3 | 4 | return sum(Math.floor(num / 10)) + num % 10; 5 | } 6 | 7 | const num = 1234; 8 | 9 | console.log(sum(num, 0)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/10Aug/Create a basic homepage with four list items ensuring all text are emboldened/style.css: -------------------------------------------------------------------------------- 1 | header { 2 | color: Red; 3 | font-size: 40px; 4 | text-align: center; 5 | } 6 | 7 | 8 | header,li { 9 | font-weight: bold; 10 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/6aug/b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/6aug/b.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/6aug/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Login 8 | 9 | 10 |
11 | 12 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/8aug/aman.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/8aug/aman.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/8aug/computer pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/8aug/computer pic.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/8aug/desktop pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/8aug/desktop pic.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/8aug/desktop pic2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/8aug/desktop pic2.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/8aug/istockphoto-1335422806-1024x1024.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/8aug/istockphoto-1335422806-1024x1024.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/assignment/8aug/vecteezy_abstract-white-podium-with-wall-scene-for-product-display_8694447.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/assignment/8aug/vecteezy_abstract-white-podium-with-wall-scene-for-product-display_8694447.jpg -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/classDesk/22 Aug/js/call back hell.js: -------------------------------------------------------------------------------- 1 | function simpleFun() { 2 | 3 | setTimeout(() =>{ 4 | console.log("Data from api 1"); 5 | 6 | setTimeout(()=> { 7 | 8 | console.log("Data from api 2"); 9 | 10 | setTimeout(() => { 11 | 12 | console.log("Data from api 3"); 13 | 14 | setTimeout(() => { 15 | console.log("Data from api 4") 16 | }, 2000) 17 | 18 | },4000) 19 | 20 | }, 2000) 21 | 22 | }, 5000) 23 | 24 | 25 | setTimeout(() => { 26 | console.log("This is another api") 27 | }, 6000) 28 | } 29 | 30 | simpleFun(); -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/classDesk/22 Aug/js/calling external api.js: -------------------------------------------------------------------------------- 1 | async function getdata(){ 2 | let respone = await fetch("https:covid19.mathdro.id/api"); 3 | let data = await respone.json(); 4 | return data; 5 | } 6 | 7 | getdata().then((d) => { 8 | console.log(d.confirmed.value); 9 | }) -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/classDesk/22 Aug/js/promise.js: -------------------------------------------------------------------------------- 1 | function promiseExmaple() { 2 | 3 | let iserror = false; 4 | 5 | return new Promise((resolve, reject) => { 6 | let data = "hello" 7 | let error = null; 8 | setTimeout(() => { 9 | if(iserror === false) { 10 | resolve(data); 11 | } else { 12 | reject(error) 13 | } 14 | }) 15 | }) 16 | } 17 | 18 | promiseExmaple().then((d) => { 19 | console.log(d) 20 | }).catch((err) =>{ 21 | console.log(err); 22 | }) -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/classDesk/22 Aug/js/set time out.js: -------------------------------------------------------------------------------- 1 | function add(num1, num2) { 2 | console.log(`sum of num1 and num2 is ${num1 + num2}`) 3 | } 4 | 5 | 6 | /** 7 | * setTimeout is a asynchornous in nature 8 | * syntax :- setTimeout(function, time, arg1, arg2........argn); 9 | */ 10 | let timerId1 = setTimeout(add, 4000, 4, 5); // async in nature 11 | console.log(`timer is for timerID1 is ${timerId1}`) // sync in nature 12 | 13 | 14 | 15 | let timerId12 = setTimeout(add, 4000, 9, 5); // async in nature 16 | console.log(`timer is for timerID1 is ${timerId12}`)// sync in nature 17 | 18 | 19 | 20 | clearInterval(timerId1) 21 | console.log("program reached"); -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/classDesk/22 Aug/js/setInterval.js: -------------------------------------------------------------------------------- 1 | /** 2 | * setInterval allow us to run a function reapetly, after a specified time of interval 3 | * 4 | * syntax : - setInterval(function, delayTime, arg1, arg2... argn); 5 | */ 6 | 7 | 8 | function add(num1, num2) { 9 | console.log(`sum of num1 and num2 is ${num1 + num2}`) 10 | } 11 | 12 | let timerId1 = setInterval(add, 4000, 4, 5); 13 | 14 | console.log("timer id is " +timerId1); 15 | 16 | // clearInterval(timerId1) -------------------------------------------------------------------------------- /ReLevel By Unacademy/html/classDesk/6Aug/part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/html/classDesk/6Aug/part1.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/16June/assignment2.js: -------------------------------------------------------------------------------- 1 | function rearrange(arr, n) { 2 | let mid = 0; 3 | let end = n-1; 4 | let swap = 0; 5 | while (mid <= end) { 6 | if (arr[mid] >= 0) { 7 | mid++; 8 | } else { 9 | swap = arr[end]; 10 | arr[end] = arr[mid]; 11 | arr[mid] = swap; 12 | end--; 13 | } 14 | } 15 | return arr; 16 | } 17 | 18 | 19 | 20 | 21 | let arr = [ -1, 2, -3, 4, 5, 6, -7, 8, 9 ]; 22 | let n = arr.length; 23 | console.log(rearrange(arr, n)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/18June/assignment.js: -------------------------------------------------------------------------------- 1 | // 1) Write a program to multiply the value in the given array and return a result (use array functions) 2 | 3 | 4 | let array = [1, 2, 3, 4, 5, 6, 7]; 5 | 6 | array.forEach((x) => console.log(x*x)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/18June/assignment2.js: -------------------------------------------------------------------------------- 1 | // 2) Write a JavaScript program to sort by id an array of JavaScript objects. 2 | 3 | 4 | const objects = [ 5 | { 6 | Id: 45, 7 | userName: "Aman" 8 | 9 | }, 10 | 11 | { 12 | Id: 22, 13 | userName: "Banti" 14 | }, 15 | 16 | { 17 | Id: 14, 18 | userName: "Jeevendra" 19 | } 20 | 21 | ]; 22 | 23 | console.log(objects); 24 | 25 | 26 | // incomplete -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/20June/assignment2.js: -------------------------------------------------------------------------------- 1 | // 2. Write a program to get an input (‘How are you’) and by default it should be good in the prompt text 2 | // box. 3 | 4 | // const readline = require('readline'); 5 | 6 | // const rl = readline.createInterface({ 7 | // input: process.stdin, 8 | // output: process.stdout, 9 | // }); 10 | 11 | // rl.question("How are you ", function (answer) { 12 | // console.log(`oh, so your name is ${answer}`); 13 | // console.log("Closing the interface"); 14 | // rl.close(); 15 | // }); 16 | 17 | let greet = prompt("How are you?", "I am Good"); 18 | console.log(greet); 19 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/20May/Assignment1/palindromes.js: -------------------------------------------------------------------------------- 1 | function palindromes(num) { 2 | if (num === 1) { 3 | console.log(num) 4 | return 1; 5 | } 6 | for (let i = 1; i <= num; i++) { 7 | if (i < 10) { 8 | console.log(i) 9 | // continue; 10 | } 11 | if(i >= 10 && i <= 50){ 12 | let temp = i % 10; 13 | let tempd = Math.floor(i / 10); 14 | if(temp === tempd) 15 | console.log(i); 16 | } 17 | } 18 | 19 | } 20 | 21 | palindromes(50); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/20May/Assignment1/tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | // if (num > 10) { 2 | // console.log(i) 3 | // // continue; 4 | // } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/20May/Assignment2.js/possitive_integer.js: -------------------------------------------------------------------------------- 1 | function squareSum(num){ 2 | var a = 0; 3 | while(a * a < num){ 4 | var b = 0; 5 | while(b * b < num){ 6 | if(a * a + b * b === num){ 7 | if(a <= b){ 8 | console.log(a + "," + b); 9 | } 10 | } 11 | b += 1; 12 | } 13 | a += 1; 14 | } 15 | } 16 | 17 | squareSum(50); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/21June/assignment2.js: -------------------------------------------------------------------------------- 1 | // Question 2: Write a program to sort a given data using recursive approach. 2 | 3 | function sortRecursive(arr, n) { 4 | if (n <= 1) 5 | return; 6 | 7 | sortRecursive(arr, n - 1); 8 | 9 | let last = arr[n - 1]; 10 | 11 | let j = n - 2; 12 | 13 | while (j >= 0 && arr[j] > last) { 14 | 15 | arr[j + 1] = arr[j]; 16 | 17 | j--; 18 | } 19 | 20 | arr[j + 1] = last; 21 | } 22 | 23 | let arr = [5, 6, 35, 89, 14, 56, 26, 19, 65, 38, 44]; 24 | 25 | sortRecursive(arr, arr.length); 26 | console.log(arr); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/21June/assignment4.js: -------------------------------------------------------------------------------- 1 | // Question 4: Write a program using recursion to print a triangle of length n. 2 | // Input: 5 3 | // Output: 4 | // * 5 | // * * 6 | // * * * 7 | // * * * * 8 | // * * * * * 9 | 10 | function printn(num) { 11 | 12 | if (num == 0) 13 | return; 14 | document.write("* "); 15 | 16 | printn(num - 1); 17 | } 18 | n 19 | 20 | function pattern(n, i) { 21 | 22 | if (n == 0) 23 | return; 24 | printn(i); 25 | document.write("
"); 26 | 27 | pattern(n - 1, i + 1); 28 | } 29 | 30 | var n = 5; 31 | pattern(n, 1); 32 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/21May/assignment1.js: -------------------------------------------------------------------------------- 1 | /* Requirements: "Write a function astroguru that: 2 | A. Takes four arguments: number of children, spouses name, location, and job 3 | B. Output the following string: “You will be a ‘job’ in ‘location’ and married to ‘partner’ with ‘numkids’.” 4 | */ 5 | 6 | function astroguru(num_Of_Children, spouses_name, location, job){ 7 | 8 | return console.log(`You will be a ${job} in ${location} and married to ${spouses_name} with ${num_Of_Children}.`) 9 | 10 | } 11 | 12 | astroguru(2, "Aman", "India","Software Engineer"); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/21May/assignment2.js: -------------------------------------------------------------------------------- 1 | // Requirements: "2. Write a function that compares two numbers and returns the larger of the two. 2 | // Bonus: Output appropriate message if numbers cant be compared or are equal" 3 | 4 | function largerNumber(num1, num2){ 5 | largerNum = num1 > num2 ? num1 : num2; 6 | return console.log(largerNum); 7 | } 8 | 9 | largerNumber(2, 3); 10 | largerNumber(3, 2); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/23May/Assignment1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 12 | 13 | Enter Name: 14 | 15 |

16 | 17 | 18 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/23May/Assignment1/script.js: -------------------------------------------------------------------------------- 1 | var data={ 2 | 'Alex':'Developer', 3 | 'John':'Artist', 4 | 'Strek':'Singer', 5 | 'Smith':'Actor' 6 | } 7 | function designation(){ 8 | let empName=document.getElementById("name").value; 9 | if(data[empName]!= undefined){ 10 | document.getElementById("designation").innerHTML = empName + " is 11 | "+data[empName] 12 | } 13 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/28May/Assignment1.js: -------------------------------------------------------------------------------- 1 | // Requirements: "1.) Given 2 numbers as input. You need to find if they have opposite signs or not. 2 | // Input -> +123, -12 3 | // Output -> true" 4 | 5 | class MyApp{ 6 | constructor(num1, num2){ 7 | this.num1 = num1; 8 | this.num2 = num2; 9 | } 10 | oppositeSign(num1, num2) { 11 | if(num1 > 0 && num2 < 0 ) { 12 | return true; 13 | } else if (num1 < 0 && num2 > 0) { 14 | return true 15 | } else { 16 | return false; 17 | } 18 | } 19 | } 20 | 21 | let myapp1 = new MyApp; 22 | console.log(myapp1.oppositeSign(-12, -12)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/28May/assignment2.js: -------------------------------------------------------------------------------- 1 | // Requirements: "2.) Given 3 numbers. You need to find the smallest of three numbers without using comparison 2 | // operators 3 | // Input -> 12,44,2 4 | // Output -> 2" 5 | 6 | function minimum(num1, num2, num3) { 7 | let a = num1 , b = num2, c = num3; 8 | while(num1 != 0 || num2 != 0 || num3 != 0) { 9 | if(num1 === 0) { 10 | return a; 11 | } else if (num2 === 0) { 12 | return b; 13 | } else if (num3 === 0) { 14 | return c; 15 | } 16 | num1--, num2--, num3--; 17 | } 18 | } 19 | 20 | 21 | console.log(minimum(21,30,4)); 22 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/3June/assignment2.js: -------------------------------------------------------------------------------- 1 | // Write code for finding the smallest element in an array. 2 | 3 | 4 | const arr = [3, 8, 3, 1, 9, -1, -3]; 5 | 6 | function smallestElement (arr) { 7 | let length = arr.length; 8 | let smallest = arr[0] 9 | 10 | for(let i = 0; i < length; i++) { 11 | if(arr[i] < smallest) { 12 | smallest = arr[i]; 13 | } 14 | } 15 | 16 | return smallest; 17 | } 18 | 19 | console.log(smallestElement(arr)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/conditional/75%_minimum.js: -------------------------------------------------------------------------------- 1 | // Problem Statement 2 | 3 | // Given 2 numbers M and N where 4 | 5 | // M = number of lectures happened 6 | // N = number of lectures attended 7 | 8 | // Your task is to find number of lectures which need to be attended to achieve 75% attendance 9 | 10 | // For example – 11 | 12 | // Input - 13 | // M = 7, N = 6 14 | 15 | 16 | // Output - 17 | // 0 (75% attendance already achieved) 18 | 19 | console.log(requiredAttendence(100, 74)); 20 | 21 | function requiredAttendence(M, N) { 22 | let minDays = Math.floor(M * 0.75); 23 | if(N > minDays) { 24 | return 0 25 | } else { 26 | return minDays - N; 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Assignments/conditional/conditional 3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Problem Statement 3 | 4 | Given an array of three numbers. You need to find the largest among the three numbers. For example - 5 | 6 | 7 | Input - 8 | 9 | 25, 15, 20 10 | 11 | 12 | Output - 13 | 14 | 25 15 | */ 16 | 17 | const arr = [25, 20, 15]; 18 | console.log(largestNum(arr)); 19 | 20 | function largestNum (arr) { 21 | let largest = arr[0] 22 | for(let i = 1; i < arr.length; i++) { 23 | if(arr[i] > largest) { 24 | largest = arr[i] 25 | } 26 | } 27 | return largest; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question10.js: -------------------------------------------------------------------------------- 1 | // Create a pattern using ‘*’ as shown below using loops 2 | 3 | // * 4 | // *** 5 | // ***** 6 | // ******* 7 | // ********* 8 | 9 | 10 | 11 | let number_of_Row = 5; 12 | 13 | for(let row = 1; row <= number_of_Row; row++){ 14 | let blank =""; 15 | let star="*"; 16 | for(let j = row; j <= number_of_Row; j++){ 17 | blank += " "; 18 | } 19 | for(let s = 1; s< row; s++){ 20 | star += "**"; 21 | } 22 | 23 | console.log(blank+star+blank); 24 | } 25 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question12.js: -------------------------------------------------------------------------------- 1 | // Problem 12 – 2 | // Write power function for any positive integer 3 | // Hint : Power function F(x^n) = x*x*x…n times; where x is the base and n is the exponent 4 | 5 | 6 | function power(base, exponent){ 7 | let result = 1; 8 | if(exponent === undefined){ 9 | exponent = 2; 10 | } 11 | 12 | for(let i = 1; i <= exponent; i++){ 13 | result *= base; 14 | } 15 | 16 | return console.log(result); 17 | } 18 | 19 | power(2, 4); 20 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question13.js: -------------------------------------------------------------------------------- 1 | // Print all the prime number up to a given number value. 2 | 3 | let num = 2; 4 | 5 | 6 | function isprime(num){ 7 | if(num < 1){ 8 | return ; 9 | } 10 | let primeis = true; 11 | for(let i = 2; i < num; i++){ 12 | if(num % i === 0){ 13 | primeis = false; 14 | return primeis; 15 | } 16 | } 17 | return primeis; 18 | } 19 | 20 | for(let j = 2; j <= num; j++){ 21 | if(num >= j){ 22 | if(isprime(j) === true){ 23 | console.log(j); 24 | } 25 | } 26 | 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question2.js: -------------------------------------------------------------------------------- 1 | // Problem 2 – 2 | // Create a program to print the result as pass if the marks obtained is greater than or equal to 40 using ternary operator. 3 | 4 | const prompt = require('prompt-sync')(); 5 | 6 | // let a = prompt("enter your marks here"); 7 | // marks >= 40 ? console.log("pass") : console.log("fail"); 8 | const marks = prompt("Enter your marks here "); 9 | 10 | 11 | let result = marks >= 40 ? 'pass' : 'fail'; 12 | 13 | console.log(`your result is ${result}`); 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question3.js: -------------------------------------------------------------------------------- 1 | // Create a program to find if the number is positive, negative or zero. 2 | // Using switch case 3 | 4 | const prompt = require('prompt-sync')(); 5 | let num1 = parseInt(prompt()); 6 | 7 | switch (true){ 8 | case (num1 === 0): 9 | console.log('Zero') 10 | break; 11 | case (num1 > 0): 12 | console.log("positive") 13 | break; 14 | case (num1 < 0): 15 | console.log("Negative") 16 | break; 17 | 18 | default: 19 | console.log("Not a Number") 20 | 21 | 22 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question4.js: -------------------------------------------------------------------------------- 1 | // Write a program to find the HCF or GCD of two integers 2 | 3 | const prompt = require('prompt-sync')(); 4 | 5 | let num1 = parseInt(prompt("your number1 => ")) 6 | let num2 = parseInt(prompt("your number2 => ")) 7 | let small, big; 8 | if(num1 > num2){ 9 | small = num2; 10 | big = num1; 11 | }else{ 12 | small = num1; 13 | big = num2; 14 | } 15 | let hcf = 1; 16 | for(let i = 0; i <= small; i++){ 17 | if(small % i === 0 && big % i === 0){ 18 | hcf = i; 19 | } 20 | } 21 | console.log(hcf); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question5.js: -------------------------------------------------------------------------------- 1 | // Create a program to reverse a string. 2 | // Solution – 3 | // Traverse the input string from last index and add each character to a new string. Print the new 4 | // reversed string. 5 | 6 | let str = "Aman"; 7 | let length = str.length -1; 8 | let reverse = "" 9 | for(let i = length; i >= 0; i--){ 10 | reverse += str[i] 11 | } 12 | console.log(str); 13 | console.log(reverse); 14 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question6.js: -------------------------------------------------------------------------------- 1 | // Problem 6 – 2 | // Create a program to find the largest amongst given 3 numbers. 3 | 4 | const num1 = 4; 5 | const num2 = 8; 6 | const num3 = 3; 7 | 8 | 9 | let largest; 10 | 11 | if(num1 > num2 && num1 > num3){ 12 | largest = num1; 13 | } else if(num2 > num1 && num2 > num3){ 14 | largest = num2; 15 | } else { 16 | largest = num3; 17 | } 18 | 19 | console.log(largest); 20 | 21 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question7.js: -------------------------------------------------------------------------------- 1 | // Problem 7 – 2 | // Create a program to get sum of all digits of a number. 3 | 4 | let num = 456; 5 | let sum = 0; 6 | while(num != 0){ 7 | sum += num % 10; 8 | num = Math.floor(num / 10); 9 | 10 | 11 | } 12 | console.log(sum); 13 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question8.js: -------------------------------------------------------------------------------- 1 | // Problem 8 – 2 | // Find if a given number is an Armstrong number or not. 3 | // Hint : Armstrong number is a number that is equal to the sum of cubes of its digits 4 | // Solution Approach - 5 | // Find all the digits of the number (in our example find the ones, tens and hundreds place digit) and then 6 | // find their cubes and add them to validate against the original number. 7 | 8 | 9 | 10 | let num = 153; 11 | let org = num 12 | let sum = 0; 13 | let armstrong = ""; 14 | 15 | while(num > 0){ 16 | sum += ((num % 10) * (num % 10) * (num % 10)); 17 | num = Math.floor(num / 10); 18 | sum === org ? armstrong = "yes" : armstrong = "No"; 19 | } 20 | 21 | console.log(armstrong); 22 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/question9.js: -------------------------------------------------------------------------------- 1 | // Create a pattern using ‘*’ as shown below using loops. 2 | // * 3 | // ** 4 | // *** 5 | // **** 6 | // ***** 7 | 8 | let star = "*" 9 | let prtTimes = 5; 10 | 11 | for(let i = 1; i <= prtTimes; i++){ 12 | let temStar = "" 13 | for(let j = 1; j <= i; j++){ 14 | temStar += star; 15 | } 16 | console.log(temStar); 17 | } 18 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/23May/tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | ureis); 2 | // console.log(israining); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/25thMay/sum_of_digits.js: -------------------------------------------------------------------------------- 1 | // 5. Sum of Digits (15 min) : 2 | 3 | // Problem Statement: 4 | // Given a positive number you need to write a program in javascript to find the sum of the inner digits of 5 | // that number. 6 | // Example-1: 7 | // Input 2124 8 | // Output 3 9 | // Example-2: 10 | // Input 70 11 | // Output 70 12 | 13 | function sumOfInnerDigits(num){ 14 | let sum = 0; 15 | 16 | if(num < 100){ 17 | return -1; 18 | } 19 | 20 | num = Math.floor(num / 10); 21 | 22 | while(num > 9){ 23 | sum += num % 10; 24 | num = Math.floor(num /10); 25 | } 26 | 27 | return sum 28 | } 29 | 30 | let a = sumOfInnerDigits(12534); 31 | console.log(a); 32 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/binomialCoefficient.js: -------------------------------------------------------------------------------- 1 | function binomialCoefficient(n , k){ 2 | //Base cases 3 | if(k > n){ 4 | return 0; 5 | } 6 | 7 | if(k === 0 || k === n){ 8 | return 1; 9 | } 10 | 11 | return binomialCoefficient(n - 1, k - 1) + binomialCoefficient(n - 1, k); 12 | } 13 | 14 | console.log(binomialCoefficient(6, 4)); 15 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/calculate_n!.js: -------------------------------------------------------------------------------- 1 | function factorial(n){ 2 | if(n === 0){ 3 | return 1; 4 | } 5 | return n * factorial(n - 1); 6 | 7 | } 8 | 9 | console.log(factorial(5)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/equalDistribution.js: -------------------------------------------------------------------------------- 1 | // Problem - 3 2 | // Given `n` pieces of sweet, help Peter and John divide it among themselves such that both get an 3 | // equal number of sweets. Note that the sweet can not be broken into sub-pieces. You have to tell if 4 | // it is possible to make such distribution or not based upon n number of pieces. I.e., possible 5 | // outputs: `yes` or `no.` 6 | 7 | 8 | // Example-1 // Input: 8 // Output: Yes 9 | 10 | // Example-2 // Input: 7 // Output: No 11 | 12 | 13 | function distribution(n) { 14 | return n % 2 != 0 ? console.log("NO") : console.log("Yes"); 15 | } 16 | 17 | distribution(11); 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/power.js: -------------------------------------------------------------------------------- 1 | function sum(num1, num2) { 2 | ans = 1; 3 | for(let i = 1; i <= num2; i++) { 4 | ans = num1 * ans; 5 | } 6 | return console.log(ans); 7 | } 8 | 9 | sum(2, 3); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/square.js: -------------------------------------------------------------------------------- 1 | // Problem - 2 2 | // Write a program to find the square of given number from 0 to n. 3 | 4 | 5 | function squareOfNumTimes(n) { 6 | for(let i = 1; i <= n; i++) { 7 | console.log(i, " * ", i, " = " , i * i); 8 | } 9 | } 10 | 11 | squareOfNumTimes(4); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/table.js: -------------------------------------------------------------------------------- 1 | // Problem - 1 2 | // Write a program to create a Mathematical calculation table from 0 to given number n. 3 | 4 | 5 | function mathTable(table, n) { 6 | console.log("The table of ", table, " and ", n, " is :--------------->>>>>>>>>>>>>>>>>>>>>>>") 7 | for(let i = 1; i <= n; i++){ 8 | console.log(table, " * ", i, " = ", table * i); 9 | 10 | } 11 | } 12 | mathTable(5, 10); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/trailingZeros.js: -------------------------------------------------------------------------------- 1 | function trainlingZeros(num) { 2 | let sumofzeros = 0; 3 | for(let i = 5; Math.floor(num / i) >= 1; i *= 5) { 4 | sumofzeros += Math.floor(num / i); 5 | } 6 | return sumofzeros; 7 | } 8 | 9 | console.log(trainlingZeros(11)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/27May/triangle.js: -------------------------------------------------------------------------------- 1 | // Problem - 4 2 | // Given the length of three line segments as a, b, and c., Find if they can form a triangle or not? 3 | // (Students are not expected to take any user input, solve the problem using hardcoded value) 4 | // Example-1 5 | // Input: a=7,b=10,c=5 6 | // Output: Triangle 7 | 8 | function checkingTraingle(a, b, c) { 9 | if(a + b <= c || b + c <= a || c + a <= b) { 10 | return false; 11 | } 12 | return true; 13 | } 14 | 15 | if(checkingTraingle(7, 10, 5)){ 16 | console.log("Triangle") 17 | } else { 18 | console.log("Not a Triangle"); 19 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/28May/Permutation_Divisible_by_60.js: -------------------------------------------------------------------------------- 1 | // Problem Statement: 2 | // Given a number A you are supposed to take the digits of that number, and find a permutation such 3 | // that 60 becomes a factor of that permutation. If there exists such a permutation then return 1 else 0. 4 | // Input - 2340 5 | // Output - 1 6 | 7 | class MyApp{ 8 | constructor(num) { 9 | this.num = num; 10 | } 11 | 12 | isNumContainZero(num) { 13 | let rem; 14 | while(num!= 0){ 15 | 16 | } 17 | } 18 | isDivisibleBy60(num){ 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/May/31May/Data Structures Arrays and Objects (Part-1)/output_Guess.js: -------------------------------------------------------------------------------- 1 | // what is the output of the below code 2 | 3 | const car = { 4 | color: 'Black', 5 | speed: '120Kmph', 6 | brand: 'Audi', 7 | start: function () { 8 | console.log('Car started'); 9 | }, 10 | stop: function () { 11 | console.log('Car stopped'); 12 | }, 13 | } 14 | const newCar = car; 15 | newCar.brand = 'BMW'; 16 | console.log(car.brand); 17 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/august/1August OOP/new keyword.js: -------------------------------------------------------------------------------- 1 | class Demo { 2 | msg = "hello this is a message!" 3 | } 4 | console.log(Demo.msg); // undefined 5 | // we tried to fetch the “msg” directly with Classname, so we got undefined. 6 | 7 | let newDemo = new Demo(); 8 | console.log(newDemo.msg); // hello this is a message 9 | // we try to fetch the “msg” value using object “obj”, so we got the result 10 | 11 | 12 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/august/1August OOP/prototypes.js: -------------------------------------------------------------------------------- 1 | //constructor function 2 | class Person { 3 | constructor() { 4 | this.name = "John"; 5 | this.age = 23; 6 | } 7 | greet() { 8 | console.log(`Hello, ${this.name}`); 9 | } 10 | } 11 | 12 | let person1 = new Person(); 13 | 14 | 15 | 16 | Person.prototype.department = "Computer Science" 17 | 18 | let person2 = new Person(); 19 | 20 | person1.greet() 21 | console.log(person1) 22 | console.log(person2) 23 | 24 | 25 | // prototype cahining 26 | 27 | class prototypeDemo { 28 | constructor(Name) { 29 | this.Name = Name; 30 | } 31 | } 32 | 33 | var obj = new prototypeDemo("Aman"); 34 | console.log(obj) 35 | 36 | console.log(Object.getPrototypeOf(obj)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/august/3August Asyc programming part 1/3 august.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/javascript/Class Desk/august/3August Asyc programming part 1/3 august.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/august/3August Asyc programming part 1/setTimeInterval.js: -------------------------------------------------------------------------------- 1 | /* 2 | setInterval: allows us to run a function repeatedly, starting after the specified interval of time, then repeating continuously at that interval 3 | 4 | Syntax of setInterval: setInterval(function|code, delayInterval, arg1, arg2, ...., argn) 5 | */ 6 | 7 | function add(num1, num2) { 8 | console.log(`The sum of ${num1} and ${num2} is ${num1 + num2}`); 9 | } 10 | 11 | 12 | let a = setInterval(add, 100, 4, 3); 13 | 14 | // clearInterval(a);// this will clear the interval 15 | 16 | setTimeout(a, 100) 17 | 18 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/array length.js: -------------------------------------------------------------------------------- 1 | // What is the output of the below code? 2 | 3 | 4 | let array = [1, 2, 3, 4]; 5 | 6 | array[100] = 134; 7 | 8 | console.log(array.length) 9 | // Explanation: The reason for this solution is as follows: JavaScript places empty as a value for indices 3 - 99. 10 | // Thus, when you set the value of the 100th index 11 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/closure.js: -------------------------------------------------------------------------------- 1 | // closure is a combination of function and lexcical enviornment 2 | 3 | // lexcical enviornmet are those who is accessed by a function out side the function 4 | 5 | // closures are automatically created while we create a closure 6 | 7 | function outerFunction () { 8 | let data = "This is a lexcila enviornment"; 9 | 10 | function innerFunction () { 11 | console.log(data) 12 | } 13 | 14 | // innerFunction(); 15 | 16 | return innerFunction; 17 | } 18 | 19 | // calling the function here; 20 | // outerFunction(); 21 | 22 | 23 | let print = outerFunction(); 24 | 25 | print(); 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/de structuring object.js: -------------------------------------------------------------------------------- 1 | 2 | // Write a function which will assign object to another variable change of object property will not 3 | // affect the object property of another variable. 4 | 5 | 6 | let obj = { 7 | Name : "Aman", 8 | age : 22, 9 | stream : "diploma", 10 | } 11 | 12 | let obj1 = {...obj}; 13 | 14 | console.log(obj.Name); 15 | 16 | obj1.Name = "Banti"; 17 | 18 | console.log(obj.Name); 19 | 20 | 21 | // Explanation: De-structuring the object will make an copy of the 22 | // object, so changing the property of one object won’t affect the 23 | // property of another object. 24 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/find element in array.js: -------------------------------------------------------------------------------- 1 | // Write a program to find the particular element in an array using find function. (Input array: 2 | // [‘a’, ‘b’, ‘c’, ‘z’, ‘h’]) find ‘c’ 3 | 4 | 5 | let arr = ['a', 'b', 'c', 'd', 'e']; 6 | 7 | let val = 'a'; 8 | let found = arr.find((x) => x === val ); 9 | 10 | console.log(found); 11 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/guess output.js: -------------------------------------------------------------------------------- 1 | let obj = { 2 | Name : "Aman", 3 | age : 22, 4 | stream : "diploma", 5 | } 6 | 7 | let obj1 = obj; 8 | console.log(obj.Name); 9 | obj1.Name = "Banti"; 10 | 11 | console.log(obj.Name); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/object notation.js: -------------------------------------------------------------------------------- 1 | // Implement the mutation using object in javascript. 2 | // Given object 3 | const obj = { 4 | Javascript: 'hard', 5 | Java: 'easy', 6 | Python: 'medium', 7 | } 8 | // Change property of Javascript from ‘hard’ to ‘easy’ 9 | 10 | 11 | let obj1 = obj; 12 | 13 | obj1.Java = 'hard'; 14 | 15 | console.log(obj.Java); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/pass by reference.js: -------------------------------------------------------------------------------- 1 | const a = [3, 4,2,2]; 2 | 3 | let b = a; 4 | 5 | b.push(6); 6 | 7 | console.log(a); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/pass by value.js: -------------------------------------------------------------------------------- 1 | // string 2 | // number 3 | // boolean 4 | 5 | let a = 5; 6 | 7 | let b = a; 8 | b = b + 5; 9 | console.log(a); 10 | console.log(b); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/18June/sort containing string.js: -------------------------------------------------------------------------------- 1 | // Write a program array containing string and sort the string array in descending order. (Input 2 | // array: [a’, ‘b’, ‘c’, ‘z’, ‘h’]) 3 | // Explanation: sort function will accept comparator passing localeCompare and comparing the 4 | // string. 5 | 6 | 7 | 8 | // solution 9 | 10 | 11 | const array = ['a', 'b', 'z', 'h']; 12 | 13 | 14 | // decreament order 15 | 16 | array.sort((a, b) => b.localeCompare(a)); 17 | 18 | console.log(array); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question1.js: -------------------------------------------------------------------------------- 1 | // Simple Destructuring assignment on Object 2 | 3 | let newAvenger = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 4 | 5 | let { realName, city, heroName } = newAvenger; 6 | console.log(realName); // Tony Stark 7 | console.log(city); // California 8 | console.log(heroName); // Iron Man 9 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question10.js: -------------------------------------------------------------------------------- 1 | let newAvenger = { 2 | realName: "Tony Stark", 3 | location: { 4 | country: "USA", 5 | city: "California" 6 | }, 7 | heroName: "Iron Man" 8 | }; 9 | let { 10 | realName: foo, 11 | location: { 12 | country: bar, 13 | city: x 14 | }, 15 | } = newAvenger; 16 | console.log(foo); // Tony Stark 17 | console.log(bar); // USA 18 | console.log(x); // California -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question11.js: -------------------------------------------------------------------------------- 1 | let newAvenger = { 2 | realName: "Tony Stark", country: "USA", city: ["California", "Malibu"], heroName: "Iron Man" 3 | }; 4 | let { realName, country, ...restOfDetails } = newAvenger; 5 | console.log(realName); // "Tony Stark" 6 | console.log(restOfDetails); // { city: [ 'California', 'Malibu' ], heroName: 'Iron Man' } 7 | // The object elements/properties which do not have the corresponding variable names are assigned to the rest of 8 | // the details. -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question2.js: -------------------------------------------------------------------------------- 1 | let { realName, city, heroName } = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 2 | 3 | console.log(realName); // Tony Stark 4 | console.log(city); // California 5 | console.log(heroName); // Iron Man -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question4.js: -------------------------------------------------------------------------------- 1 | let newAvenger = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 2 | 3 | let realName, city, heroName; 4 | 5 | ({ realName, city, heroName } = newAvenger); 6 | 7 | console.log(realName); // Tony Stark 8 | console.log(city); // California 9 | console.log(heroName); // Iron Man 10 | 11 | 12 | // Note: 13 | // We have the same variable names as declared inside the object. 14 | // Let's see what we get if the names are different. -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question5.js: -------------------------------------------------------------------------------- 1 | let newAvenger = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 2 | let realName, location, heroName; 3 | ({ realName, location, heroName } = newAvenger); 4 | console.log(realName); // Tony Stark 5 | console.log(location); // undefined 6 | console.log(heroName); // Iron Man 7 | 8 | 9 | // As we have used a "location" instead of "city," we get undefined as a result. 10 | // Object Destructuring using new variable name: 11 | // In case we want to use different names, we can do that as below -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question6.js: -------------------------------------------------------------------------------- 1 | let newAvenger = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 2 | 3 | let realName, location, heroName; 4 | 5 | ({ realName: fooName, city: location, heroName: barName } = newAvenger); 6 | 7 | console.log(fooName); // Tony Stark 8 | console.log(location); // California 9 | console.log(barName); // Iron Man 10 | 11 | // Here we have assigned the values to fooName, location and barName. 12 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question7.js: -------------------------------------------------------------------------------- 1 | let newAvenger = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 2 | 3 | let { realName = 'Downey Jr', location = 'Malibu', heroName = 'Allu Arjun' } = newAvenger; 4 | 5 | console.log(realName); // Tony Stark 6 | console.log(location); // Malibu 7 | console.log(heroName); // Iron Man 8 | 9 | // Here the realName was changed to "Tony Stark," but the location had the default value as "Malibu" as there is no 10 | // corresponding element location in the extracted object. -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question8.js: -------------------------------------------------------------------------------- 1 | // Using Computed property name, we can specify the name of a property via an expression if we put it in square 2 | // brackets: 3 | // Note that the property name should be a string. 4 | let prop = "realName"; 5 | let { [prop]: foo } = { realName: 'Tony Stark', city: 'California', heroName: 'Iron Man' }; 6 | console.log(foo); // Tony Stark -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/question9.js: -------------------------------------------------------------------------------- 1 | // We can also use arrays with objects in object destructuring. 2 | // Example 9: 3 | 4 | let newAvenger = { realName: "Tony Stark", city: ["California", "Malibu"], heroName: "Iron Man" }; 5 | let { realName: foo, city: bar } = newAvenger; 6 | console.log(foo); // Tony Stark 7 | console.log(bar); // ["California", "Malibu"] -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/1June/object destructing/without_destructuring.js: -------------------------------------------------------------------------------- 1 | // Without Object destructuring we access the object items as below 2 | 3 | let heroNames = { 4 | bollywood : "Akshay Kumar", 5 | south : "Nitin", 6 | 7 | } 8 | 9 | let bollywoodHero = heroNames.bollywood; 10 | 11 | console.log(bollywoodHero); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/20June/class desk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/javascript/Class Desk/june/20June/class desk.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/20June/currying.js: -------------------------------------------------------------------------------- 1 | // Currying 2 | // • Currying is when you break down a function that takes 3 | // multiple arguments into a series of function that each take 4 | // only one argument. 5 | // • In the below example curryAdd function is returning a series 6 | // of function and at the last function it is returning the value. 7 | 8 | 9 | 10 | const add = (a, b, c) => { 11 | return a + b + c; 12 | } 13 | 14 | 15 | const curryAdd = (num) => { 16 | return (a) => { 17 | return (b) => { 18 | return (c) => { 19 | return add(a, b,c); 20 | } 21 | } 22 | } 23 | } 24 | 25 | const adddtion = curryAdd(add); 26 | 27 | console.log(adddtion(1)(2)(3)) -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/20June/higher order function.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 2, 3, 4, 5]; 2 | 3 | const filter = arr.filter(function(item){ 4 | return item > 3 5 | }) 6 | 7 | console.log(filter); 8 | 9 | 10 | //sorting 11 | 12 | const sorting = arr.sort(function(a, b){ 13 | return b - a; 14 | }) 15 | 16 | console.log(sorting); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/21June/classdesk 21 june.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/javascript/Class Desk/june/21June/classdesk 21 june.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/21June/json.js: -------------------------------------------------------------------------------- 1 | const emplooyes = { 2 | 3 | 4 | "name" : "Banti", 5 | "age" : 22 6 | 7 | 8 | } 9 | 10 | console.log(emplooyes.name); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/22June/class desk 22 june.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/javascript/Class Desk/june/22June/class desk 22 june.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/25June/Maximize Pairwise Sum.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | 3 | 4 | // works in browser 5 | // error in sort in vs code 6 | function findMaxSumOfPairs(arr) { 7 | arr = arr.sort((a, b) => a > b); 8 | 9 | let maxSum = 0; 10 | 11 | for (let i = 0; i < arr.length; i = i + 2) { 12 | maxSum = maxSum + arr[i]; 13 | } 14 | 15 | return maxSum; 16 | } 17 | 18 | 19 | 20 | let arr = [2, 1, 3, 4] 21 | arr = arr.sort((a, b) => a > b); 22 | console.log(arr) 23 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/25June/calss desk 25 june.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/ReLevel By Unacademy/javascript/Class Desk/june/25June/calss desk 25 june.pdf -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/8June/Transpose of a matrix(In-place).js: -------------------------------------------------------------------------------- 1 | //Transpose of a matrix 2 | //(i, j) => (j, i) 3 | //In-place transpose 4 | function transpose(A) { 5 | for (let i = 0; i < A.length; i++) { 6 | for (let j = i + 1; j < A[0].length; j++) { 7 | 8 | let temp = A[i][j]; 9 | A[i][j] = A[j][i]; 10 | A[j][i] = temp; 11 | 12 | } 13 | } 14 | 15 | return A; 16 | } 17 | 18 | let A = [ 19 | [1, 2, 3], 20 | [4, 5, 6], 21 | [7, 8, 9] 22 | ] 23 | console.log(transpose(A)) 24 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/8June/create a 2D array.js: -------------------------------------------------------------------------------- 1 | // Way to create a 2D array 2 | //3 rows and 4 columns -> 3 x 4 3 | let matrix = new Array(3); //[] 4 | 5 | for (let i = 0; i < 3; i++) { 6 | matrix[i] = new Array(4); 7 | } 8 | 9 | console.log(matrix); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/8June/foreach.js: -------------------------------------------------------------------------------- 1 | //For each loop in a 2D array 2 | let arr = [ 3 | [3, 4, 5, 6], // 0th index 4 | [4, 1, -2, 0], // 1st index 5 | [2, 9, 0, 6] // 2nd index 6 | ] 7 | 8 | 9 | arr.forEach(ele => ele.forEach(x => console.log(x))) 10 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/Class Desk/june/8June/transpose of a matrix.js: -------------------------------------------------------------------------------- 1 | //Transpose of a matrix 2 | //(i, j) => (j, i) 3 | //Here we will use a new matrix for transpose 4 | function transpose(A) { 5 | //Created a new matrix which has same rows and columns as A 6 | 7 | let B = new Array(A.length); 8 | 9 | for(let i = 0; i < A.length;i++) { 10 | B[i] = new Array(A[0].length); 11 | } 12 | 13 | for(let i = 0; i < A.length; i++) { 14 | 15 | for(let j = 0; j < A[0].length; j++) { 16 | B[i][j] = A[j][i]; 17 | } 18 | } 19 | 20 | return B; 21 | 22 | } 23 | 24 | let A = [ 25 | [1, 2, 3], 26 | [4, 5, 6], 27 | [7, 8, 9] 28 | ] 29 | console.log(transpose(A)) 30 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/examTest/Counting Valleys.js: -------------------------------------------------------------------------------- 1 | function countingValleys(steps, path) { 2 | // Write your code here 3 | 4 | let valley = 0; 5 | 6 | let sealLevel = 0; 7 | 8 | for (let i = 0; i < path.length; i++) { 9 | 10 | if (path[i] === "U") { 11 | 12 | sealLevel++ 13 | } 14 | 15 | else { 16 | 17 | if (sealLevel === 0) valley++; 18 | 19 | sealLevel--; 20 | } 21 | } 22 | 23 | return valley; 24 | 25 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/examTest/DIVISIBILITY BY K.js: -------------------------------------------------------------------------------- 1 | function divisibilityByK(arr, n, k) { 2 | 3 | let total = 0; 4 | 5 | 6 | let ans = 0; 7 | 8 | for (let i = 0; i < arr.length; i++) { 9 | 10 | total += arr[i]; 11 | 12 | if (total % k === 0) { 13 | total = 0; 14 | continue; 15 | 16 | } 17 | 18 | let temp = total + 1; 19 | 20 | if (temp % k === 0) { 21 | ans++; 22 | total = 0; 23 | continue; 24 | } 25 | 26 | temp = total - 1; 27 | 28 | if (temp % k === 0) { 29 | ans++; 30 | total = 0; 31 | continue; 32 | } 33 | 34 | } 35 | 36 | return ans; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/examTest/Divisible Sum Pairs.js: -------------------------------------------------------------------------------- 1 | function divisibleSumPairs(n, k, arr) { 2 | // Write your code here 3 | let count = 0; 4 | arr.sort() 5 | 6 | for (let i = 0; i < n - 1; i++) { 7 | 8 | for (let j = i + 1; j < n; j++) { 9 | 10 | if ((arr[i] + arr[j]) % k === 0) count++ 11 | } 12 | } 13 | return count; 14 | 15 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/examTest/Mini-Max Sum.js: -------------------------------------------------------------------------------- 1 | function miniMaxSum(arr) { 2 | // Write your code here 3 | 4 | let sum = 0; 5 | arr.sort(); 6 | 7 | for (let i = 0; i < arr.length; i++) { 8 | sum += arr[i]; 9 | } 10 | console.log(sum - arr[arr.length - 1], sum - arr[0]); 11 | } -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/examTest/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Calculator

8 |

Enter the values in the prompt

9 |

Click on any of the below buttons to perform calculations

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/examTest/police_of_Berland.js: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | // 0 0 1 0 1 0 4 | // 0 -> non engineers 5 | // 1 -> engineers 6 | 7 | 8 | function numOfHouses(array){ 9 | let lenngth = array.length - 1; 10 | let count = 0; 11 | for(let i = 1; i < lenngth; i++){ 12 | if(array[i] === 1 && array[i - 1] === 0 && array[i + 1] === 0 ){ 13 | count += 1; 14 | i += 1; 15 | } 16 | } 17 | return count; 18 | } 19 | 20 | const array = [0, 0, 1, 0, 1, ] 21 | console.log(numOfHouses(array)); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/notes_for_javascript_with_code/input: -------------------------------------------------------------------------------- 1 | const prompt = require('prompt-sync')(); 2 | let num = parseInt(prompt("Enter your number here ")); -------------------------------------------------------------------------------- /ReLevel By Unacademy/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "prompt-sync": "^4.2.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /geeks for geeks solution/Dsa/Next Greater Element.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @param {BigInt[]} arr 4 | * @param {number} n 5 | * @returns {BigInt[]} 6 | */ 7 | class Solution { 8 | //Function to find the next greater element for each element of the array. 9 | nextLargerElement(arr, n) { 10 | // code here 11 | 12 | let stack = []; 13 | let result = []; 14 | 15 | for (let i = n - 1; i >= 0; i--) { 16 | 17 | while (stack.length && stack[stack.length - 1] <= arr[i]) { 18 | stack.pop(); 19 | } 20 | 21 | result[i] = stack.length === 0 ? -1 : stack[stack.length - 1]; 22 | stack.push(arr[i]); 23 | } 24 | return result; 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /geeks for geeks solution/bit magic/Power of 2.js: -------------------------------------------------------------------------------- 1 | function isPowerofTwo(n) { 2 | // code here 3 | 4 | let curr = 0; 5 | let i = 0; 6 | 7 | while (curr <= n) { 8 | 9 | curr = Math.pow(2, i); 10 | i++; 11 | } 12 | 13 | 14 | 15 | if (curr == n) return "yes" 16 | return "No" 17 | 18 | } 19 | 20 | 21 | console.log(isPowerofTwo(23)) -------------------------------------------------------------------------------- /hackerrank challenge/DS/array/left rotation.js: -------------------------------------------------------------------------------- 1 | 2 | // solution 1 3 | function rotateLeft(d, arr) { 4 | // Write your code here 5 | 6 | d = d % arr.length; 7 | let rArr = []; 8 | 9 | for (let i = 0; i < arr.length; i++) { 10 | 11 | let idx = (i + d) % arr.length; 12 | 13 | rArr[i] = arr[idx]; 14 | 15 | } 16 | 17 | return rArr; 18 | 19 | } 20 | 21 | 22 | 23 | // solution 2; 24 | 25 | function rotateLeft(d, arr) { 26 | // Write your code here 27 | 28 | let rotation = d % arr.length; 29 | 30 | const roted = [...arr.slice(rotation), ...arr(0, arr.length)] 31 | 32 | return roted; 33 | 34 | } -------------------------------------------------------------------------------- /hackerrank challenge/DS/linked list/Insert a Node at the Tail of a Linked List.js: -------------------------------------------------------------------------------- 1 | function insertNodeAtTail(head, data) { 2 | 3 | const newNode = SinglyLinkedListNode(data); 4 | 5 | if (!head) return newNode; 6 | 7 | let currentNode = head.next; 8 | 9 | while (currentNode.next) currentNode = currentNode.next; 10 | 11 | currentNode.next = newNode; 12 | 13 | return head; 14 | 15 | } -------------------------------------------------------------------------------- /hackerrank challenge/DS/stack/Poisonous Plants.js: -------------------------------------------------------------------------------- 1 | function poisonousPlants(p) { 2 | // Write your code here 3 | 4 | 5 | let days = 0; 6 | 7 | for (let i = 1; i < p.length; i++) { 8 | 9 | let curr = p[i - 1]; 10 | let max = 0; 11 | if (curr < p[i] ) { 12 | while (curr < p[i] && i < p.length) { 13 | i++; 14 | max++; 15 | 16 | console.log(curr, p[i], max, days) 17 | } 18 | 19 | } 20 | 21 | days = Math.max(days, max); 22 | 23 | } 24 | return days; 25 | 26 | } 27 | 28 | console.log(poisonousPlants([3, 2, 5, 4])) -------------------------------------------------------------------------------- /hackerrank challenge/DS/stack/and xor or.js: -------------------------------------------------------------------------------- 1 | function andXorOr(a) { 2 | 3 | let stack = []; 4 | 5 | let maxResult = 0; 6 | 7 | for (let i = 0; i < a.length; i++) { 8 | 9 | while (stack.length > 0) { 10 | 11 | let x = a[i] ^ stack[stack.length - 1]; 12 | 13 | maxResult = Math.max(maxResult, x); 14 | 15 | if (a[i] < stack[stack.length - 1]) stack.pop(); 16 | 17 | else break; 18 | 19 | } 20 | stack.push(a[i]); 21 | } 22 | 23 | return maxResult; 24 | } 25 | 26 | 27 | console.log(andXorOr([9, 6, 3, 5, 2])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Bill Division.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/contests/mountblue-technologies/challenges/bon-appetit 2 | 3 | 4 | function bonAppetit(bill, k, b) { 5 | // Write your code here 6 | let total = 0; 7 | for (let i = 0; i < bill.length; i++) { 8 | if (i !== k) { 9 | total += bill[i]; 10 | } 11 | } 12 | let result = total / 2; 13 | if (result === b) { 14 | console.log("Bon Appetit"); 15 | } else { 16 | console.log(b - result); 17 | } 18 | 19 | 20 | 21 | 22 | } 23 | 24 | let bill = [4, 1] 25 | let k = [3, 10, 2, 9]; 26 | let b = 12; 27 | 28 | 29 | 30 | console.log(bonAppetit(bill, k, b)); -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Breaking the Records.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function breakingRecords(scores) { 4 | // Write your code here 5 | 6 | let max = scores[0]; 7 | let min = scores[0]; 8 | let scoresIn = 0; 9 | let scoresDn = 0; 10 | 11 | for (let i = 0; i < scores.length; i++ ) { 12 | 13 | if (scores[i] > max) { 14 | max = scores[i]; 15 | scoresIn++ 16 | } 17 | 18 | if (scores[i] < min) { 19 | min = scores[i]; 20 | scoresDn++ 21 | } 22 | 23 | 24 | }; 25 | 26 | let ans = [scoresIn, scoresDn]; 27 | return ans; 28 | 29 | } 30 | 31 | 32 | let arr = [10, 5, 20, 20, 4, 5, 2, 25, 1] 33 | console.log(breakingRecords(arr)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Caesar Cipher.js: -------------------------------------------------------------------------------- 1 | function caesarCipher(s, k) { 2 | // Write your code here 3 | let ans = "" 4 | 5 | k = k % 26; 6 | 7 | for (let i = 0; i < s.length; i++) { 8 | 9 | let tempCode = s.charCodeAt(i); 10 | 11 | 12 | if ((tempCode <= 122 && tempCode >= 97)) { 13 | 14 | tempCode += k; 15 | if (tempCode > 122) tempCode -= 26; 16 | 17 | } else if (tempCode >= 65 && tempCode <= 90) { 18 | 19 | tempCode += k; 20 | if (tempCode > 90) tempCode -= 26; 21 | 22 | } 23 | ans += String.fromCharCode(tempCode); 24 | 25 | } 26 | 27 | return ans; 28 | } -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/CamelCase.js: -------------------------------------------------------------------------------- 1 | 2 | function camelcase(s) { 3 | // Write your code here 4 | 5 | if (s.length <= 1) return s.length; 6 | let word = 1; 7 | 8 | for (let i = 0; i < s.length; i++) { 9 | 10 | let charCode = s.charCodeAt(i); 11 | 12 | if (charCode >= 65 && charCode <= 90) word++; 13 | 14 | } 15 | return word; 16 | 17 | } 18 | 19 | 20 | // optimized solution; 21 | 22 | function camelcase(s) { 23 | // Use a regular expression to count the number of capital letters in the string 24 | return (s.match(/[A-Z]/g) || []).length + 1; 25 | } 26 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Compare the Triplets.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/contests/mountblue-technologies/challenges/compare-the-triplets 2 | 3 | 4 | function compareTriplets(a, b) { 5 | 6 | let alice = 0; 7 | let bob = 0; 8 | 9 | for (let i = 0; i < a.length; i++) { 10 | if (a[i] > b[i]) { 11 | alice++; 12 | } else if (a[i] < b[i]) { 13 | bob++; 14 | } 15 | } 16 | 17 | return [alice, bob]; 18 | 19 | } 20 | 21 | 22 | console.log(compareTriplets([17, 28, 30], [99, 16, 8])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Game of Thrones - I.js: -------------------------------------------------------------------------------- 1 | 2 | function gameOfThrones(s) { 3 | // Write your code here 4 | 5 | let freqMap = new Array(26).fill(0); 6 | 7 | for (let i = 0; i < s.length; i++) { 8 | let charCode = s.charCodeAt(i) - 97; 9 | 10 | freqMap[charCode]++; 11 | }; 12 | 13 | 14 | let count = 0; 15 | 16 | for (let i = 0; i < 26; i++) { 17 | 18 | if (freqMap[i] === 1 || freqMap[i] % 2 === 1) { 19 | 20 | if (count) { 21 | return "NO" 22 | } else { 23 | count++; 24 | } 25 | } 26 | 27 | 28 | } 29 | return "YES"; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Halloween Sale.js: -------------------------------------------------------------------------------- 1 | function howManyGames(p, d, m, s) { 2 | // Return the number of games you can buy 3 | 4 | 5 | let sum = 0; 6 | let count = 0; 7 | 8 | while (sum <= s) { 9 | 10 | sum += p; 11 | 12 | if (p - d > m) p -= d; 13 | else p = m; 14 | 15 | count++; 16 | } 17 | return sum === s ? count : count -= 1; 18 | 19 | } -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Jumping on the Clouds Revisited.js: -------------------------------------------------------------------------------- 1 | // Complete the jumpingOnClouds function below. 2 | function jumpingOnClouds(c, k) { 3 | let n = c.length; 4 | let energy = 100; 5 | 6 | let jump = (0 + k) % n; 7 | 8 | c[jump] === 1 ? energy -= 3 : energy -= 1; 9 | 10 | 11 | while (jump) { 12 | 13 | jump = (jump + k) % n; 14 | c[jump] === 1 ? energy -= 3 : energy -= 1; 15 | } 16 | return energy; 17 | } 18 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Largest Permutation.js: -------------------------------------------------------------------------------- 1 | 2 | function largestPermutation(k, arr) { 3 | // Write your code here 4 | 5 | 6 | for (let i = 0; i < arr.length; i++) { 7 | let temp = i; 8 | for (let j = i + 1; j < arr.length; j++) { 9 | 10 | if (arr[j] > arr[temp]) { 11 | 12 | temp = j 13 | } 14 | } 15 | if (temp !== i) { 16 | [arr[i], arr[temp]] = [arr[temp], arr[i]]; 17 | k--; 18 | } 19 | if (k === 0) break; 20 | } 21 | return arr; 22 | 23 | } -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Making Anagrams.js: -------------------------------------------------------------------------------- 1 | 2 | function makingAnagrams(s1, s2) { 3 | // Write your code here 4 | let freqMap = new Array(26).fill(0) 5 | 6 | for (let i = 0; i < s1.length; i++) { 7 | 8 | let ind = s1.charCodeAt(i) - 97; 9 | 10 | freqMap[ind]++; 11 | } 12 | 13 | 14 | for (let i = 0; i < s2.length; i++) { 15 | 16 | let ind = s2.charCodeAt(i) - 97; 17 | freqMap[ind]--; 18 | } 19 | 20 | let count = 0; 21 | 22 | for (let i = 0; i < 26; i++) { 23 | 24 | count += Math.abs(freqMap[i]); 25 | } 26 | return count; 27 | 28 | } -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Mark and Toys.js: -------------------------------------------------------------------------------- 1 | 2 | function maximumToys(prices, k) { 3 | // Write your code here 4 | 5 | 6 | prices.sort((a, b) => a - b); 7 | 8 | let sum = 0; 9 | let i = 0; 10 | let count = 0; 11 | 12 | 13 | for (i = 0; i < prices.length; i++) { 14 | 15 | if ((sum += prices[i]) < k) count++; 16 | 17 | else return count; 18 | 19 | 20 | } 21 | 22 | return count; 23 | 24 | } 25 | 26 | console.log(climbingLeaderboard([1, 12, 5, 111, 200, 1000, 10], 50)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Max Min.js: -------------------------------------------------------------------------------- 1 | function maxMin(k, arr) { 2 | // Write your code here 3 | 4 | arr.sort((a, b) => a - b); 5 | 6 | let min = Infinity; 7 | 8 | for(let i = 0; i < arr.length - k; i++) { 9 | 10 | if(arr[i + k - 1] - arr[i] < min) min = arr[i + k - 1] - arr[i]; 11 | } 12 | return min; 13 | 14 | 15 | 16 | 17 | } -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Missing Numbers.js: -------------------------------------------------------------------------------- 1 | function missingNumbers(arr, brr) { 2 | 3 | const freq1 = new Array(10001).fill(0); 4 | const freq2 = new Array(10001).fill(0); 5 | const result = []; 6 | 7 | for (const num of arr) { 8 | freq1[num]++; 9 | } 10 | 11 | for (const num of brr) { 12 | freq2[num]++; 13 | } 14 | 15 | 16 | for (let i = 1; i <= 10000; i++) { 17 | if (freq2[i] > freq1[i]) { 18 | result.push(i); 19 | } 20 | } 21 | 22 | return result; 23 | } 24 | 25 | arr = [11, 4, 11, 7, 13, 4, 12, 11, 10, 14] 26 | brr = [11, 4, 11, 7, 3, 7, 10, 13, 4, 8, 12, 11, 10, 14, 12] 27 | 28 | console.log(missingNumbers(arr, brr)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Modified Kaprekar Numbers.js: -------------------------------------------------------------------------------- 1 | function kaprekarNumbers(p, q) { 2 | // Write your code here 3 | const ans = [] 4 | if (p <= 8) { 5 | ans.push(1); 6 | p = 8; 7 | } 8 | 9 | while (p <= q) { 10 | let sqare = Math.pow(p, 2).toString(); 11 | let len = Math.floor(sqare.length / 2); 12 | let arr = [sqare.slice(0, len), sqare.slice(len, sqare.length)]; 13 | console.log(p, arr) 14 | if (Number(arr[0]) + Number(arr[1]) === p) ans.push(p); 15 | p++; 16 | } 17 | ans.length === 0 ? console.log("INVALID RANGE") : console.log(ans); 18 | 19 | } 20 | 21 | console.log(kaprekarNumbers(1, 100)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Number Line Jumps.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/contests/mountblue-technologies/challenges/kangaroo 2 | 3 | function kangaroo(x1, v1, x2, v2) { 4 | // Write your code here 5 | if ((x2 > x1 && v2 >= v1) || (x1 > x2 && v1 >= v2)) { 6 | return "NO"; 7 | } 8 | 9 | if ((x2 - x1) % (v1 - v2) === 0) { 10 | return "YES"; 11 | } 12 | 13 | return "NO"; 14 | 15 | } 16 | 17 | 18 | console.log(kangaroo(4, 2, 0, 3)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Permuting Two Arrays.js: -------------------------------------------------------------------------------- 1 | function twoArrays(k, A, B) { 2 | // Write your code here 3 | A.sort((a, b) => a - b); 4 | 5 | B.sort((a, b) => a - b); 6 | console.log(A); 7 | console.log(B); 8 | console.log(k) 9 | 10 | for (let i = 0; i < A.length; i++) { 11 | 12 | if (A[i] + B[i] < k) return "NO"; 13 | 14 | 15 | 16 | } 17 | return "YES" 18 | 19 | } 20 | 21 | const A = [1, 3, 2]; 22 | const B = [] 23 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Running Time of Algorithms.js: -------------------------------------------------------------------------------- 1 | 2 | function runningTime(arr) { 3 | // Write your code here 4 | 5 | let iterationTime = 0; 6 | 7 | for (let i = 1; i < arr.length; i++) { 8 | 9 | let j = i - 1; 10 | 11 | let currVal = arr[i]; 12 | 13 | while (j >= 0 && arr[j] > currVal) { 14 | 15 | arr[j + 1] = arr[j]; 16 | j--; 17 | iterationTime += 1; 18 | } 19 | 20 | arr[j + 1] = currVal; 21 | } 22 | console.log(arr) 23 | return iterationTime; 24 | 25 | } 26 | 27 | // console.log(runningTime([1, 1, 2, 2, 3, 3, 5, 5, 7, 7, 9, 9])) 28 | console.log(runningTime([2, 1, 3, 1, 2])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Sales by Match.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/contests/mountblue-technologies/challenges/sock-merchant 2 | 3 | function sockMerchant(n, ar) { 4 | // Write your code here 5 | 6 | let pairs = 0; 7 | 8 | 9 | if (n <= 1) return 0; 10 | 11 | let map = new Map(); 12 | 13 | for (let i = 0; i < n; i++) { 14 | 15 | if (map.has(ar[i])) { 16 | map.delete(ar[i]); 17 | pairs++; 18 | } else { 19 | map.set(ar[i]); 20 | } 21 | } 22 | return pairs; 23 | 24 | } 25 | 26 | 27 | let n = 9 28 | const ar = [10, 20, 20, 10, 10, 30, 50, 10, 20] 29 | 30 | 31 | console.log(sockMerchant(n, ar)); -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Sansa and XOR.js: -------------------------------------------------------------------------------- 1 | 2 | function sansaXor(arr) { 3 | // Write your code here 4 | 5 | let sum = 0; 6 | let xSum = 0; 7 | 8 | for (let i = 0; i < arr.length; i++) { 9 | 10 | sum = sum ^ arr[i]; 11 | xSum = arr[i]; 12 | 13 | for (let j = i + 1; j < arr.length; j++) { 14 | 15 | xSum = xSum ^ arr[j]; 16 | sum = sum ^ xSum; 17 | } 18 | } 19 | return sum; 20 | 21 | } 22 | 23 | console.log(sansaXor([3, 4, 5])) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Simple Array Sum.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/contests/mountblue-technologies/challenges/simple-array-sum/problem 2 | function simpleArraySum(ar) { 3 | // Write your code here 4 | 5 | let sum = 0; 6 | 7 | ar.forEach(element => { 8 | sum += element 9 | }); 10 | 11 | return sum; 12 | 13 | } 14 | 15 | 16 | console.log(simpleArraySum([1, 3, 4])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Staircase.js: -------------------------------------------------------------------------------- 1 | function staircase(n) { 2 | // Write your code here 3 | 4 | let hash = "#" 5 | 6 | for (let i = 0; i < n; i++) { 7 | let space = "" 8 | for (let j = 0; j < n - i - 1; j++) { 9 | 10 | space += " " 11 | } 12 | 13 | console.log(space + hash) 14 | hash += "#" 15 | } 16 | 17 | } 18 | 19 | 20 | console.log(staircase(4)); -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Strange Counter.js: -------------------------------------------------------------------------------- 1 | function strangeCounter(t) { 2 | 3 | let value = 3; 4 | 5 | 6 | 7 | while (t > value) { 8 | 9 | t -= value; 10 | value *= 2; 11 | 12 | 13 | 14 | } 15 | 16 | return (value - t + 1); 17 | } 18 | 19 | 20 | 21 | 22 | 23 | const x = 4; 24 | console.log(strangeCounter(14)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Super Reduced String.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/contests/mountblue-technologies/challenges/reduced-string 2 | 3 | 4 | function superReducedString(s) { 5 | // Write your code here 6 | 7 | let arr = s.split(""); 8 | let i = 0; 9 | 10 | while (i < arr.length) { 11 | 12 | if (arr[i] === arr[i + 1]) { 13 | arr.splice(i, 2); 14 | i = 0; 15 | } else { 16 | i++ 17 | } 18 | } 19 | 20 | return arr.length ? arr.join("") : "Empty String" 21 | 22 | 23 | } 24 | 25 | // let a = "baab"; 26 | 27 | // test case 1 28 | let a = "aaabccddd"; 29 | 30 | 31 | 32 | console.log(superReducedString(a)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/The Love-Letter Mystery.js: -------------------------------------------------------------------------------- 1 | function theLoveLetterMystery(s) { 2 | // Write your code here 3 | 4 | let i = 0; 5 | let j = s.length - 1; 6 | let count = 0; 7 | 8 | while (i < j) { 9 | 10 | if (s[i] !== s[j]) { 11 | const code1 = s.charCodeAt(i); 12 | const code2 = s.charCodeAt(j); 13 | count += Math.abs(code1 - code2); 14 | } 15 | i++; 16 | j--; 17 | } 18 | return count; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/Viral Advertising.js: -------------------------------------------------------------------------------- 1 | function viralAdvertising(n) { 2 | // Write your code here 3 | 4 | let liked = 2; 5 | let communicate = 2; 6 | 7 | let shared = 5; 8 | for (let i = 2; i <= n; i++) { 9 | 10 | shared = liked * 3; 11 | liked = Math.floor(shared / 2); 12 | communicate += liked 13 | 14 | 15 | } 16 | 17 | return communicate; 18 | 19 | } -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/angry professor.js: -------------------------------------------------------------------------------- 1 | function angryProfessor(k, a) { 2 | // Write your code here 3 | 4 | let onTime = 0; 5 | 6 | for (let i = 0; i < a.length; i++) if (a[i] <= 0) onTime++; 7 | 8 | return onTime - k >= 0 ? "YES" : "NO" 9 | 10 | } 11 | 12 | console.log(angryProfessor(3, [-1, -3, 2, 4])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/append and delete.js: -------------------------------------------------------------------------------- 1 | function appendAndDelete(s, t, k) { 2 | // Write your code here 3 | 4 | let i = 0, j = 0; 5 | 6 | while (i < s.length && j < t.length) { 7 | if (s[i] === t[j]) { 8 | i++; 9 | j++; 10 | } else { 11 | break; 12 | } 13 | } 14 | 15 | let left = (s.length - i ) + (t.length - j ); 16 | 17 | 18 | 19 | 20 | if (k >= left && (k - left) % 2 === 0 || k >= s.length + t.length) { 21 | return "Yes"; 22 | } else { 23 | return "No"; 24 | } 25 | } 26 | 27 | 28 | console.log(appendAndDelete("ashley", "ash", 2)) //NO 29 | console.log(appendAndDelete("hackerhappy", "hackerrank", 9)) // YES -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/beautifulDays.js: -------------------------------------------------------------------------------- 1 | function beautifulDays(i, j, k) { 2 | // Write your code here 3 | 4 | let bDay = 0; 5 | while (i <= j) { 6 | 7 | 8 | let reversed = Number(String(i).split("").reverse().join("")); 9 | let absDiff = Math.abs(i - reversed); 10 | 11 | if (absDiff % k === 0) bDay++; 12 | 13 | i++; 14 | } 15 | return bDay; 16 | } 17 | 18 | 19 | console.log(beautifulDays(20, 23, 6)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/beautifulTriplets.js: -------------------------------------------------------------------------------- 1 | function beautifulTriplets(d, arr) { 2 | // Write your code here 3 | 4 | // arr.sort((a, b) => a - b); 5 | 6 | let set = new Set(); 7 | 8 | for (let i in arr) { 9 | set.add(arr[i]); 10 | } 11 | 12 | let count = 0; 13 | 14 | for (let i = 0; i < arr.length; i++) { 15 | 16 | let a = arr[i] 17 | 18 | if (set.has(a + d)) { 19 | 20 | let b = (a + d); 21 | 22 | 23 | if (set.has(b + d)) count++; 24 | } 25 | } 26 | return count; 27 | 28 | } 29 | 30 | console.log(beautifulTriplets(3, [1, 2, 4, 5, 7, 8, 10])) 31 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/chocolateFeast.js: -------------------------------------------------------------------------------- 1 | function chocolateFeast(n, c, m) { 2 | // Write your code here 3 | 4 | 5 | let choclate =Math.floor( n / c); 6 | 7 | let cover = choclate; 8 | 9 | let coverLeft = 0; 10 | let i = 0; 11 | while (cover >= m) { 12 | 13 | let newChoclate = Math.floor(cover / m); 14 | 15 | choclate += newChoclate; 16 | 17 | coverLeft = cover % m; 18 | 19 | cover = newChoclate + coverLeft; 20 | 21 | console.log(cover, coverLeft); 22 | if (i === 5) break; 23 | i++; 24 | 25 | 26 | } 27 | 28 | return choclate; 29 | } 30 | 31 | console.log(chocolateFeast(12, 4, 4)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/circular array rotation.js: -------------------------------------------------------------------------------- 1 | function gamingArray(arr) { 2 | // Write your code here 3 | 4 | let max = 0; 5 | 6 | let count = 0; 7 | 8 | for (let i = 0; i < arr.length; i++) { 9 | if (max < arr[i]) { 10 | max = arr[i]; 11 | count++; 12 | } 13 | } 14 | return count % 2 === 0 ? "ANDY" : "BOB"; 15 | 16 | } 17 | console.log(circularArrayRotation([3, 4, 5], 2, [1, 2])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/counter game.js: -------------------------------------------------------------------------------- 1 | function counterGame(n) { 2 | // Write your code here 3 | 4 | if (n == 1) return "Richard"; 5 | 6 | let count = 0; 7 | 8 | while (n !== 1) { 9 | 10 | // console.log(Math.pow(n, 0.5)) 11 | 12 | if (Math.pow(n, 0.5) === Math.floor(Math.pow(n, 0.5))) n = n / 2; 13 | 14 | else if (n === 2) n = 1; 15 | else n = n - Math.pow(2, Math.floor(Math.pow(n, 0.5))); 16 | // console.log(n) 17 | count++; 18 | console.log(count) 19 | 20 | 21 | } 22 | 23 | return count % 2 === 0 ? "Louise" : "Richard" 24 | 25 | } 26 | 27 | 28 | console.log(counterGame(6)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/equalizeArray.js: -------------------------------------------------------------------------------- 1 | 2 | function equalizeArray(arr) { 3 | // Write your code here 4 | 5 | let hasMap = {}; 6 | 7 | for (let i = 0; i < arr.length; i++) { 8 | 9 | if (arr[i] in hasMap) { 10 | 11 | hasMap[arr[i]] = ++hasMap[arr[i]]; 12 | } 13 | 14 | else hasMap[arr[i]] = 1; 15 | 16 | 17 | } 18 | 19 | let max = -Infinity; 20 | for (let i in hasMap) { 21 | max = Math.max(max, hasMap[i]) 22 | 23 | } 24 | return arr.length - max; 25 | 26 | } 27 | 28 | console.log(equalizeArray([1, 3, 4, 5, 3, 2, 3, 5])); -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/ermutationEquation.js: -------------------------------------------------------------------------------- 1 | function permutationEquation(p) { 2 | // Write your code here 3 | let map = new Map(); 4 | 5 | for (let i = 0; i < p.length; i++) { 6 | 7 | map.set(p[i], i) 8 | 9 | } 10 | 11 | let ans = []; 12 | 13 | for (let i = 0; i < p.length; i++) { 14 | 15 | let temp = map.get(i + 1) + 1; 16 | 17 | 18 | 19 | let val = map.get(temp); 20 | 21 | ans.push(val + 1) 22 | 23 | } 24 | 25 | return ans 26 | 27 | } 28 | 29 | console.log(permutationEquation([5, 2, 1, 3, 4])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/gridChallenge.js: -------------------------------------------------------------------------------- 1 | function gridChallenge(grid) { 2 | // Write your code here 3 | 4 | for (let i = 0; i < grid.length; i++) { 5 | grid[i] = grid[i].split("").sort().join("") 6 | } 7 | 8 | for (let i = 0; i < grid.length; i++) { 9 | 10 | for (let j = 0; j < grid[0].length - 1; j++) { 11 | 12 | if (grid[j][i] > grid[j+ 1][i]) return false; 13 | } 14 | 15 | } 16 | return true; 17 | 18 | } 19 | let grid = ['ebacd', 'abghij', 'olmkn', 'trpqs', 'xywuv'] 20 | console.log(gridChallenge(grid)) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/hurdleRace.js: -------------------------------------------------------------------------------- 1 | function hurdleRace(k, height) { 2 | // Write your code here 3 | let max = Math.max(...height); 4 | return max > k ? max - k : 0; 5 | 6 | } 7 | 8 | 9 | console.log(hurdleRace(7, [1, 6, 3, 5, 2])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/insertion sort 1.js: -------------------------------------------------------------------------------- 1 | function insertionSort1(n, arr) { 2 | // Write your code here 3 | let i = arr.length - 2; 4 | n = arr[n - 1]; 5 | while (i >= 0 && arr[i] > n) { 6 | 7 | arr[i + 1] = arr[i]; 8 | console.log(arr) 9 | i--; 10 | } 11 | arr[i + 1] = n; 12 | return arr; 13 | 14 | } 15 | 16 | 17 | console.log(insertionSort1(5 , [ 2, 4, 6, 8, 3 ])) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/insertion sort 2.js: -------------------------------------------------------------------------------- 1 | function insertionSort2(n, arr) { 2 | // Write your code here 3 | 4 | for (let i = 1; i < n; i++) { 5 | 6 | let j = i - 1; 7 | let currVal = arr[i]; 8 | 9 | while (j >= 0 && arr[j] > currVal) { 10 | arr[j + 1] = arr[j] 11 | j--; 12 | 13 | } 14 | arr[j + 1] = currVal; 15 | console.log(arr.toString().replace(/,/g, " ")); 16 | 17 | } 18 | 19 | 20 | } 21 | 22 | insertionSort2(5, [1, 4, 3, 6, 2 ]) -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/pangrams.js: -------------------------------------------------------------------------------- 1 | 2 | function pangrams(s) { 3 | // Write your code here 4 | 5 | s = s.toLowerCase(); 6 | 7 | let arr = new Array(26).fill(1); 8 | 9 | 10 | for (let i = 0; i < s.length; i++) { 11 | if (s[i] === " ") continue; 12 | let char = s.charCodeAt(i) - 97; 13 | 14 | arr[char]--; 15 | } 16 | console.log(arr) 17 | 18 | for (let i = 0; i < 26; i++) { 19 | console.log(arr[i]) 20 | if (arr[i] >= 1) return "not pangram"; 21 | } 22 | return "pangram"; 23 | 24 | } 25 | 26 | console.log(pangrams("We promptly judged antique ivory buckles for the next prize")) 27 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/plus minus.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function plusMinus(arr) { 4 | // Write your code here 5 | 6 | let possitive = 0; 7 | let negative = 0; 8 | let zero = 0; 9 | 10 | for (let i = 0; i < arr.length; i++) { 11 | if (arr[i] === 0) zero++; 12 | else if (arr[i] > 0) possitive++; 13 | else negative++; 14 | 15 | 16 | } 17 | console.log(possitive / arr.length); 18 | console.log(negative / arr.length); 19 | console.log(zero / arr.length); 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/sepreate numbers.js: -------------------------------------------------------------------------------- 1 | 2 | function separateNumbers(s) { 3 | 4 | // Write your code here 5 | if (s[0] == 0 || s.length <= 1) return console.log("NO"); 6 | 7 | for (let i = 0; i < s.length / 2; i++) { 8 | 9 | let subStr = s.slice(0, i + 1); 10 | 11 | let num = BigInt(subStr); 12 | 13 | let validStr = subStr; 14 | 15 | while (validStr.length < s.length) validStr += String(++num); 16 | 17 | if (validStr == s) return console.log("YES " + subStr); 18 | 19 | } 20 | 21 | return console.log("NO") 22 | } 23 | 24 | 25 | separateNumbers("99999999999100000001") 26 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/squares.js: -------------------------------------------------------------------------------- 1 | 2 | function squares(a, b) { 3 | // Write your code here 4 | 5 | let square = 0 6 | let num = a; 7 | for (let i = a; i <= b; i++) { 8 | 9 | 10 | if (Number.isInteger(Math.pow(i, 0.5))) { 11 | square++; 12 | num = Math.pow(i, 0.5); 13 | 14 | break; 15 | 16 | } 17 | 18 | 19 | } 20 | if (square) { 21 | square--; 22 | 23 | while (num * num <= b) num++, square++; 24 | } 25 | return square; 26 | 27 | } 28 | 29 | console.log(squares(3, 10)) 30 | 31 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/sumXor.js: -------------------------------------------------------------------------------- 1 | function sumXor(n) { 2 | let count = 0; 3 | if (n === 0) return 1; 4 | 5 | // Count number of zeros in binary representation of n 6 | let binaryStr = n.toString(2); 7 | let numZeros = 0; 8 | for (let i = 0; i < binaryStr.length; i++) { 9 | if (binaryStr.charAt(i) === '0') { 10 | numZeros++; 11 | } 12 | } 13 | 14 | // Calculate number of combinations that result in sum equal to xor 15 | count = BigInt(1) << BigInt(numZeros); 16 | 17 | return count; 18 | } 19 | -------------------------------------------------------------------------------- /hackerrank challenge/MountBlue Job Challenge/taum and B'day.js: -------------------------------------------------------------------------------- 1 | function taumBday(b, w, bc, wc, z) { 2 | // Calculate cost of black gifts 3 | let minBC = Math.min(bc, wc + z); 4 | let costBC = BigInt(b) * BigInt(minBC); 5 | 6 | // Calculate cost of white gifts 7 | let minWC = Math.min(wc, bc + z); 8 | let costWC = BigInt(w) * BigInt(minWC); 9 | 10 | // Calculate total cost 11 | let totalCost = costBC + costWC; 12 | 13 | return totalCost.toString(); 14 | 15 | } 16 | 17 | const b = 3, w = 6, bc = 9, wc = 1, z = 1 18 | console.log(taumBday(b, w, bc, wc, z)); 19 | -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/bit manipulation/Counter game.js: -------------------------------------------------------------------------------- 1 | 2 | function counterGame(n) { 3 | // Write your code here 4 | while (n !== 1) { 5 | 6 | let p = Math.sqrt(n, 0.5); 7 | 8 | let p1 = parseInt(p); 9 | 10 | if (p === p1) n = p; 11 | else n = n - Math.pow(p1, 2); 12 | console.log(p, p1, n) 13 | 14 | // if (p === ) 15 | } 16 | 17 | return n; 18 | } 19 | 20 | console.log(counterGame(132)) 21 | 22 | 23 | console.log(Math.sqrt(5, 0.5)) -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/bit manipulation/Lonely Integer.js: -------------------------------------------------------------------------------- 1 | function lonelyinteger(a) { 2 | // Write your code here 3 | let ans = 0; 4 | for (let i = 0; i < a.length; i++) { 5 | 6 | ans = ans ^ a[i]; 7 | } 8 | 9 | return ans; 10 | 11 | } -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/string/CamelCase.js: -------------------------------------------------------------------------------- 1 | function camelcase(s) { 2 | // Write your code here 3 | 4 | if (s.length === 0) return 0; 5 | if (s.length === 1) return 1; 6 | 7 | 8 | let letters = 1; 9 | 10 | 11 | for (let i = 0; i < s.length; i++) { 12 | 13 | 14 | let char = s.charCodeAt(i); 15 | 16 | if (char >= 65 && char <= 90) letters++; 17 | } 18 | 19 | return letters; 20 | 21 | } -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/string/The Love-Letter Mystery.js: -------------------------------------------------------------------------------- 1 | function theLoveLetterMystery(s) { 2 | // Write your code here 3 | let len = s.length; 4 | 5 | let count = 0; 6 | for (let i = 0; i < len / 2; i++) { 7 | 8 | count += Math.abs(s.charCodeAt(i) - s.charCodeAt(len - i - 1)); 9 | } 10 | 11 | return count; 12 | 13 | } 14 | 15 | 16 | console.log(theLoveLetterMystery("cba")) 17 | -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/string/Weighted Uniform Strings.js: -------------------------------------------------------------------------------- 1 | function weightedUniformStrings(s, queries) { 2 | // Write your code here 3 | let map = new Map(); 4 | let len = 0; 5 | for (let i = 0; i < s.length; i++) { 6 | 7 | let charCode = s.charCodeAt(i) - 96; 8 | if (s[i] === s[i - 1]) len += charCode; 9 | else len = charCode; 10 | map.set(len) 11 | 12 | 13 | } 14 | const ans = [] 15 | 16 | for (let i = 0; i < queries.length; i++) { 17 | 18 | map.has(queries[i]) ? ans.push("Yes") : ans.push("No"); 19 | } 20 | 21 | return ans; 22 | 23 | 24 | } 25 | 26 | console.log(weightedUniformStrings("abccddde")) 27 | -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/string/funny Strings.js: -------------------------------------------------------------------------------- 1 | 2 | function funnyString(s) { 3 | // Write your code here 4 | let arr = []; 5 | 6 | for (let i = 0; i < s.length; i++) { 7 | 8 | let charCode = s.charCodeAt(i); 9 | arr.push(charCode); 10 | } 11 | 12 | 13 | 14 | for (let i = 0; i < arr.length - 1; i++) { 15 | 16 | let a = Math.abs(arr[i] - arr[i + 1]); 17 | let b = Math.abs(arr[arr.length - i - 1] - arr[arr.length - i - 2]); 18 | 19 | if (a !== b) return "Not Funny" 20 | } 21 | 22 | return "Funny"; 23 | } -------------------------------------------------------------------------------- /hackerrank challenge/algorithms/string/pangram.js: -------------------------------------------------------------------------------- 1 | function pangrams(s) { 2 | // Write your code here 3 | let set = new Set(); 4 | 5 | for (let i = 0; i < s.length; i++) { 6 | 7 | if (s[i] === " ") continue; 8 | 9 | let char = s[i].toLowerCase(); 10 | set.add(char); 11 | } 12 | 13 | 14 | return set.size === 26 ? "pangram" : "not pangram"; 15 | } 16 | 17 | 18 | const letter = "We promptly judged antique ivory buckles for the next prize" 19 | 20 | console.log(pangrams(letter)) 21 | 22 | -------------------------------------------------------------------------------- /js advance/different types ofselectors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /js advance/different types ofselectors/script.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: black; 3 | color: whitesmoke; 4 | } -------------------------------------------------------------------------------- /js advance/different types ofselectors/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/js advance/different types ofselectors/style.css -------------------------------------------------------------------------------- /leet Code/121. Best Time to Buy and Sell Stock.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} prices 3 | * @return {number} 4 | */ 5 | var maxProfit = function (prices) { 6 | 7 | let buy = prices[0]; 8 | let ind = 0; 9 | for (let i = 0; i < prices.length; i++) { 10 | if (prices[i] < buy) { 11 | buy = prices[i]; 12 | ind = i; 13 | } 14 | 15 | } 16 | 17 | let sell = buy; 18 | 19 | 20 | for (i = ind ; i < prices.length; i++) { 21 | if (prices[i] > sell) { 22 | sell = prices[i] 23 | } 24 | console.log(i) 25 | } 26 | 27 | return sell - buy 28 | 29 | 30 | }; 31 | 32 | console.log(maxProfit([2, 4, 1])) -------------------------------------------------------------------------------- /leet Code/144. Binary Tree Preorder Traversal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {number[]} 12 | */ 13 | var preorderTraversal = function (root) { 14 | var ans = []; 15 | 16 | preOrder(root, ans); 17 | return ans; 18 | 19 | }; 20 | 21 | function preOrder(root, ans) { 22 | if (!root) return; 23 | 24 | ans.push(root.val); 25 | preOrder(root.left, ans); 26 | preOrder(root.right, ans) 27 | } -------------------------------------------------------------------------------- /leet Code/145. Binary Tree Postorder Traversal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {number[]} 12 | */ 13 | var postorderTraversal = function (root) { 14 | 15 | var ans = []; 16 | 17 | postOrder(root, ans); 18 | return ans; 19 | 20 | }; 21 | 22 | function postOrder(root, ans) { 23 | 24 | if (!root) return; 25 | 26 | postOrder(root.left, ans); 27 | postOrder(root.right, ans); 28 | 29 | ans.push(root.val) 30 | } -------------------------------------------------------------------------------- /leet Code/1486. XOR Operation in an Array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @param {number} start 4 | * @return {number} 5 | */ 6 | var xorOperation = function (n, start) { 7 | let ans = 0; 8 | 9 | for (let i = 0; i < n; i++) { 10 | 11 | ans ^= start + 2 * i; 12 | 13 | } 14 | 15 | return ans; 16 | }; -------------------------------------------------------------------------------- /leet Code/1684. Count the Number of Consistent Strings.js: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/count-the-number-of-consistent-strings/description/ 2 | 3 | /** 4 | * @param {string} allowed 5 | * @param {string[]} words 6 | * @return {number} 7 | */ 8 | var countConsistentStrings = function (allowed, words) { 9 | 10 | 11 | let map = new Map(); 12 | 13 | for (let i of allowed) map.set(i); 14 | 15 | let count = 0; 16 | for (let i of words) { 17 | 18 | let consistent = true; 19 | for (let j of i) { 20 | 21 | if (!map.has(j)) { 22 | consistent = false; 23 | break; 24 | } 25 | } 26 | if (consistent) count++; 27 | } 28 | return count; 29 | 30 | }; -------------------------------------------------------------------------------- /leet Code/1704. Determine if String Halves Are Alike.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {boolean} 4 | */ 5 | var halvesAreAlike = function (s) { 6 | 7 | let vowel = "aeiouAEIOU" 8 | 9 | let left = 0 10 | let rigth = 0; 11 | 12 | 13 | for (let i = 0; i < s.length / 2; i++) { 14 | 15 | if (vowel.includes(s.charAt(i))) left++; 16 | 17 | if (vowel.includes(s.charAt(s.length - i - 1))) rigth++; 18 | 19 | 20 | } 21 | 22 | return left === rigth; 23 | 24 | }; -------------------------------------------------------------------------------- /leet Code/1720. Decode XORed Array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} encoded 3 | * @param {number} first 4 | * @return {number[]} 5 | */ 6 | var decode = function (encoded, first) { 7 | 8 | const orignal_array = [first]; 9 | 10 | for (let i = 0; i < encoded.length; i++) { 11 | 12 | orignal_array.push(orignal_array[i] ^ encoded[i]); 13 | } 14 | return orignal_array 15 | 16 | 17 | }; -------------------------------------------------------------------------------- /leet Code/191. Number of 1 Bits.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n - a positive integer 3 | * @return {number} 4 | */ 5 | var hammingWeight = function (n) { 6 | 7 | n = n.toString(2); 8 | 9 | let count = 0; 10 | 11 | for (let i of n) if (i == 1) count++; 12 | 13 | return count; 14 | 15 | }; -------------------------------------------------------------------------------- /leet Code/22. Generate Parentheses.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {string[]} 4 | */ 5 | const generateParenthesis = (n) => { 6 | 7 | let ans = [] 8 | const go = (start, end, s) => { 9 | 10 | if (s.length === 2 * n) { 11 | ans.push(s); 12 | return; 13 | } 14 | 15 | if (start < n) go(start + 1, end, s + "("); 16 | if (end < start) go(start, end + 1, s + ")"); 17 | } 18 | 19 | go(0, 0, "") 20 | 21 | return ans; 22 | }; 23 | 24 | // https://embed.creately.com/cclS6u7Upy3?type=svg 25 | 26 | console.log(generateParenthesis(3)) -------------------------------------------------------------------------------- /leet Code/229. Majority Element II.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var majorityElement = function (nums) { 6 | 7 | 8 | let map = {}; 9 | let max = Math.floor(nums.length / 3); 10 | 11 | 12 | for (i of nums) { 13 | 14 | map[i] = (map[i] || 0) + 1; 15 | 16 | } 17 | 18 | 19 | let ans = []; 20 | 21 | 22 | for (i in map) if (map[i] > max) ans.push(Number(i)); 23 | 24 | return ans; 25 | 26 | }; 27 | 28 | console.log(majorityElement([3, 2, 3])) -------------------------------------------------------------------------------- /leet Code/2405. Optimal Partition of String.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | var partitionString = function (s) { 6 | 7 | 8 | let set = new Set() 9 | 10 | let subStr = "" 11 | 12 | 13 | for (let i = 0; i < s.length; i++) { 14 | 15 | subStr += s[i] 16 | 17 | if (set.has(subStr) || set.has(s[i])) { 18 | subStr = s[i] 19 | 20 | } 21 | 22 | else { 23 | set.add(subStr) 24 | // subStr = "" 25 | } 26 | } 27 | 28 | console.log(set) 29 | 30 | return set.size; 31 | }; 32 | 33 | 34 | console.log(partitionString("abacaba")) 35 | 36 | 37 | // console.log(partitionString("ssssss")) -------------------------------------------------------------------------------- /leet Code/2460. Apply Operations to an Array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var applyOperations = function (nums) { 6 | const n = nums.length 7 | for (let i = 0; i < n - 1; i++) { 8 | if (nums[i] === nums[i + 1]) { 9 | nums[i] *= 2 10 | nums[i + 1] = 0 11 | } 12 | } 13 | const res = nums.filter(e => e !== 0) 14 | while (res.length !== n) res.push(0) 15 | return res 16 | 17 | }; 18 | 19 | const arr =[847, 847, 0, 0, 0, 399, 416, 416, 879, 879, 206, 206, 206, 272]; 20 | // const [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; 21 | console.log(applyOperations(arr)); -------------------------------------------------------------------------------- /leet Code/2620. Counter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {Function} counter 4 | */ 5 | var createCounter = function (n) { 6 | 7 | return function () { 8 | return n++; 9 | }; 10 | }; 11 | 12 | /** 13 | * const counter = createCounter(10) 14 | * counter() // 10 15 | * counter() // 11 16 | * counter() // 12 17 | */ -------------------------------------------------------------------------------- /leet Code/268. Missing Number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var missingNumber = function (nums) { 6 | 7 | 8 | // for (let i = 0; i <= nums.length; i++) { 9 | 10 | // if (!nums.includes(i)) return i; 11 | 12 | // } 13 | 14 | let len = nums.length + 1; 15 | 16 | let sum = len * (len - 1) / 2 17 | 18 | nums.forEach(a => sum -= a); 19 | 20 | return sum 21 | 22 | }; 23 | 24 | console.log(missingNumber([0, 1])) -------------------------------------------------------------------------------- /leet Code/3. Longest Substring Without Repeating Characters.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {number} 4 | */ 5 | var lengthOfLongestSubstring = function (s) { 6 | 7 | let len = s.length; 8 | 9 | let map = new Map(); 10 | let max = 0; 11 | let curr = 0, i = 0 12 | 13 | if (len <= 1) return len; 14 | 15 | while( i < len) { 16 | 17 | if (!map.has(s[i])) { 18 | 19 | map.set(s[i]); 20 | i++; 21 | 22 | 23 | } else { 24 | map.delete(s[curr]) 25 | curr++; 26 | } 27 | max = Math.max(max, map.size); 28 | 29 | } 30 | 31 | return max 32 | 33 | 34 | }; 35 | console.log(lengthOfLongestSubstring("pwwkwe")) 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /leet Code/42. Trapping Rain Water.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} height 3 | * @return {number} 4 | */ 5 | var trap = function (height) { 6 | 7 | let left_nge = [height[0]]; 8 | 9 | let right = 0; 10 | let ans = 0; 11 | 12 | for (let i = 1; i < height.length; i++) { 13 | 14 | left_nge[i] = Math.max(left_nge[i - 1], height[i]); 15 | } 16 | 17 | 18 | 19 | for (let i = height.length - 1; i >= 0; i--) { 20 | 21 | right = Math.max(right, height[i]) 22 | 23 | ans += (Math.min(left_nge[i], right) - height[i]) 24 | 25 | 26 | } 27 | 28 | return ans; 29 | }; -------------------------------------------------------------------------------- /leet Code/496. Next Greater Element I.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums1 3 | * @param {number[]} nums2 4 | * @return {number[]} 5 | */ 6 | var nextGreaterElement = function (nums1, nums2) { 7 | 8 | let result = []; 9 | 10 | for (let i = 0; i < nums1.length; i++) { 11 | 12 | let temp = nums1[i]; 13 | 14 | let ind = nums2.indexOf(temp); 15 | let g = -1; 16 | 17 | for (let j = ind + 1; j < nums2.length; j++) { 18 | 19 | if (temp < nums2[j]) { 20 | g = nums2[j] 21 | break; 22 | } 23 | } 24 | result.push(g); 25 | } 26 | return result; 27 | }; -------------------------------------------------------------------------------- /leet Code/50. Pow(x, n).js: -------------------------------------------------------------------------------- 1 | // Implement pow(x, n), which calculates x raised to the power n(i.e., xn). 2 | 3 | 4 | 5 | // Example 1: 6 | 7 | // Input: x = 2.00000, n = 10 8 | // Output: 1024.00000 9 | // Example 2: 10 | 11 | // Input: x = 2.10000, n = 3 12 | // Output: 9.26100 13 | // Example 3: 14 | 15 | // Input: x = 2.00000, n = -2 16 | // Output: 0.25000 17 | // Explanation: 2 - 2 = 1 / 22 = 1 / 4 = 0.25 18 | 19 | 20 | // Constraints: 21 | 22 | // -100.0 < x < 100.0 23 | // - 231 <= n <= 231 - 1 24 | // n is an integer. 25 | // - 104 <= xn <= 104 26 | 27 | 28 | 29 | /** 30 | * @param {number} x 31 | * @param {number} n 32 | * @return {number} 33 | */ 34 | var myPow = function (x, n) { 35 | 36 | return Math.pow(x, n) 37 | 38 | }; -------------------------------------------------------------------------------- /leet Code/503. Next Greater Element II.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var nextGreaterElements = function (nums) { 6 | 7 | 8 | let stack = []; 9 | let output = []; 10 | 11 | for (let i = 2 * (nums.length - 1); i >= 0; i--) { 12 | 13 | let Index = i % nums.length; 14 | 15 | 16 | while (stack.length > 0 && nums[Index] >= nums[stack[stack.length - 1]]) { 17 | 18 | stack.pop(); 19 | } 20 | 21 | stack.length === 0 ? output[Index] = -1 : output[Index] = nums[stack[stack.length - 1]] 22 | 23 | 24 | stack.push(Index); 25 | } 26 | 27 | return output; 28 | }; 29 | const nums = [1, 2, 1]; 30 | console.log(nextGreaterElements(nums)); -------------------------------------------------------------------------------- /leet Code/7. Reverse Integer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {number} 4 | */ 5 | var reverse = function (x) { 6 | 7 | 8 | let result = 0; 9 | let sign = x < 0 ? -1 : 1; 10 | 11 | x = Math.abs(x); 12 | 13 | while (x >= 10) { 14 | 15 | result = result * 10 + x % 10; 16 | x = parseInt(x / 10); 17 | 18 | if (x < 10) { 19 | result = result * 10 + x; 20 | } 21 | } 22 | 23 | result = result * sign; 24 | 25 | if (result > Math.pow(2, 31) - 1 || result < Math.pow(-2, 31)) { 26 | return 0; 27 | } 28 | 29 | return result; 30 | 31 | 32 | 33 | }; 34 | 35 | console.log(reverse(1534236469)) -------------------------------------------------------------------------------- /leet Code/717. 1-bit and 2-bit Characters.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} bits 3 | * @return {boolean} 4 | */ 5 | var isOneBitCharacter = function (bits) { 6 | 7 | let i = 0; 8 | 9 | 10 | while (i < bits.length - 1) { 11 | 12 | bits[i] === 1 ? i += 2 : i += 1; 13 | } 14 | 15 | return i === bits.length - 1; 16 | 17 | 18 | 19 | }; -------------------------------------------------------------------------------- /leet Code/876. Middle of the Linked List.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * function ListNode(val, next) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.next = (next===undefined ? null : next) 6 | * } 7 | */ 8 | /** 9 | * @param {ListNode} head 10 | * @return {ListNode} 11 | */ 12 | var middleNode = function (head) { 13 | let start = head, end = head; 14 | let i = 1; 15 | while (end && end.next && end.next.next) { 16 | start = start.next; 17 | end = end.next.next; 18 | 19 | } 20 | 21 | if (end.next) return start.next 22 | return start 23 | 24 | }; -------------------------------------------------------------------------------- /leet Code/881. Boats to Save People.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} people 3 | * @param {number} limit 4 | * @return {number} 5 | */ 6 | var numRescueBoats = function (people, limit) { 7 | 8 | people.sort((a, b) => a - b); 9 | 10 | let boat = 0; 11 | 12 | let i = 0, j = people.length - 1; 13 | 14 | while (i <= j) { 15 | 16 | if (people[i] + people[j] <= limit) i++; 17 | 18 | boat++; 19 | j--; 20 | 21 | } 22 | 23 | return boat; 24 | 25 | }; -------------------------------------------------------------------------------- /leet Code/94. Binary Tree Inorder Traversal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {number[]} 12 | */ 13 | 14 | function inOrder(root, ans) { 15 | if (!root) return; 16 | 17 | inOrder(root.left, ans); 18 | ans.push(root.val); 19 | inOrder(root.right, ans) 20 | } 21 | 22 | var inorderTraversal = function (root) { 23 | 24 | var ans = []; 25 | 26 | inOrder(root, ans); 27 | return ans; 28 | 29 | 30 | }; -------------------------------------------------------------------------------- /leet Code/tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | ans += matrix[i][j] -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "bootstrap": "^5.2.0" 4 | }, 5 | "devDependencies": { 6 | "jshint": "^2.13.5" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /practice for FEd/aug/day46_17Aug/navbar-background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/practice for FEd/aug/day46_17Aug/navbar-background.jpg -------------------------------------------------------------------------------- /practice for FEd/aug/day46_17Aug/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/practice for FEd/aug/day46_17Aug/style.css -------------------------------------------------------------------------------- /practice for FEd/aug/day47_18Aug/Expand the Media Gallery app to have the images pop when hovered upon.js/districk koderma loga.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/practice for FEd/aug/day47_18Aug/Expand the Media Gallery app to have the images pop when hovered upon.js/districk koderma loga.png -------------------------------------------------------------------------------- /practice for FEd/aug/day49_20aug/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

11 | 12 | -------------------------------------------------------------------------------- /practice from relevel/Relevel round 2 Practice Problem/Redistribution/Redistribution.js: -------------------------------------------------------------------------------- 1 | const mod = 1000000007 2 | 3 | let currSum = 0; 4 | 5 | function findAllPossibleSolutionCount (currSum) { 6 | if(currSum === n) return 1; 7 | 8 | if(currSum > n) return 0; 9 | 10 | if(dp[currSum] !== -1) { 11 | return dp[currSum]; 12 | } 13 | 14 | let possibleSolutionCount = 0; 15 | 16 | for(let i = 3; i <= n; i + 2) { 17 | possibleSolutionCount += findAllPossibleSolutionCount(currSum + 1); 18 | } 19 | 20 | dp[currSum] = possibleSolutionCount % mod; 21 | return possibleSolutionCount % mod 22 | 23 | } 24 | 25 | 26 | var n = 890; 27 | let dp = Array(n).fill(n - 1); 28 | console.log(findAllPossibleSolutionCount(currSum)) -------------------------------------------------------------------------------- /practice from relevel/Relevel round 2 Practice Problem/Redistribution/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aman-Burnwal/javascript/8efff967b5f4c61c21181b325758f8c60eb45e83/practice from relevel/Relevel round 2 Practice Problem/Redistribution/question.png -------------------------------------------------------------------------------- /practice from relevel/Relevel round 2 Practice Problem/Redistribution/read.md: -------------------------------------------------------------------------------- 1 | video link :------- -------------------------------------------------------------------------------- /tailwindcss/another responsive card/src/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /tailwindcss/another responsive card/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [".dist/src/index.html"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tailwindcss/card/src/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | 6 | -------------------------------------------------------------------------------- /tailwindcss/card/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./dist/index.html"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tailwindcss/responsive card/src/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /tailwindcss/responsive card/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./dist/index.html"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /temp.js: -------------------------------------------------------------------------------- 1 | // your code goes here 2 | 3 | 4 | // var n = readline(); 5 | 6 | 7 | // let arr = [...n.split(", ")]; 8 | // // console.log(arr); 9 | 10 | let arr = [2, 4, 6]; 11 | console.log(findingHcf(arr)); 12 | function findingHcf(arr) { 13 | 14 | let hcf = arr[0]; 15 | for (let i = 1; i < arr.length; i++) { 16 | 17 | hcf = find(hcf, arr[i]); 18 | 19 | } 20 | 21 | return hcf; 22 | } 23 | 24 | // console.log(arr) 25 | function find(hcf, val) { 26 | 27 | if (hcf > val) [hcf, val] = [val, hcf]; 28 | 29 | for (let i = hcf; i >= 1; i--) { 30 | 31 | if (val % i === 0) return i; 32 | } 33 | 34 | } 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | // this.len++; 2 | --------------------------------------------------------------------------------