Skip to content

Instantly share code, notes, and snippets.

View ujjawalsidhpura's full-sized avatar
🙂

Ujjawal Sidhpura ujjawalsidhpura

🙂
View GitHub Profile
@ujjawalsidhpura
ujjawalsidhpura / enable-ga-tracking-using-gtag.html
Last active October 9, 2024 10:09
web-vitals-tracking-code
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID');
</script>
function Division(num1, num2) {
let num1Factors = [];
let num2Factors = [];
let commonFactors = []
for (let i = 1; i < num1; i++) {
if (num1 % i === 0) {
num1Factors.push(i)
}
function PalindromeTwo(str) {
let tempStr = [];
let straightStr = [];
let reverseStr;
let res = true;
let string =
str.split(' ').join(' ').toLowerCase().split('').forEach(element => {
if (element.match(/[a-z]/g)) {
@ujjawalsidhpura
ujjawalsidhpura / readme.txt
Last active September 5, 2021 18:49
Run Length
Have the function RunLength(str) take the str parameter being passed and
return a compressed version of the string using the Run-length encoding algorithm.
This algorithm works by taking the occurrence of each repeating character and outputting
that number along with a single character of the repeating sequence. For example: "wwwggopp" would return 3w2g1o2p.
The string will not contain any numbers, punctuation, or symbols.
@ujjawalsidhpura
ujjawalsidhpura / primeTime.js
Created September 5, 2021 17:14
Prime Number ?
function PrimeTime(num) {
if (num === 2) {
return true;
}
for (let i = 2; i < num; i++) {
if (num % i !== 0) {
return true
} else {
@ujjawalsidhpura
ujjawalsidhpura / BasicRomanNumerals.js
Created September 4, 2021 22:20
Basic Roman Numerals
function BasicRomanNumerals(str) {
let arr = []
str.split('').forEach(num => {
switch (num) {
case 'I':
arr.push(1);
break;
case 'V':
arr.push(5);
@ujjawalsidhpura
ujjawalsidhpura / countingMinutes.js
Created September 2, 2021 20:56
counting minutes
function CountingMinutes(str) {
let string = str.split('-')
let start = string[0];
let end = string[1];
let output;
let minuteMaker = function (data) {
let hours;
let minutes;
let time;
@ujjawalsidhpura
ujjawalsidhpura / maxSubarray.js
Created August 25, 2021 15:31
Max sum subarray
function MaxSubArray(arr) {
let currentSum = arr[0];
let maxSum = arr[0];
for (let i = 1; i < arr.length; i++) {
currentSum = Math.max(currentSum + arr[i], arr[i])
maxSum = Math.max(maxSum, currentSum);
}
return maxSum;
@ujjawalsidhpura
ujjawalsidhpura / cipher.js
Last active September 20, 2021 21:45
Caeser Cipher
const encrypt = function (str, num) {
let string = str.split(' ').join(' ').split('');
let alphabets = 'abcdefghijklmnopqrstuvwxyz';
let capitalAlphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let alphabetsArr = alphabets.split('')
let capitalAlphabetsArr = capitalAlphabets.split('');
let x;
@ujjawalsidhpura
ujjawalsidhpura / bitwise.js
Last active September 5, 2021 18:50
bitwise.js
function BitwiseTwo(strArr) {
let x = strArr[0].split('');
let y = strArr[1].split('');
let z = [];
for (let i = 0; i < x.length; i++) {
if (x[i] === '1' && y[i] === '1') {
z[i] = '1';
} else {