Skip to content

Instantly share code, notes, and snippets.

View Sanchithasharma's full-sized avatar
😃

Sanchitha SR Sanchithasharma

😃
View GitHub Profile
@Sanchithasharma
Sanchithasharma / TextButton.stories.tsx
Created October 28, 2022 12:25
Writing story with args
import TextButton from "./TextButton"
import { ComponentMeta, ComponentStory} from "@storybook/react"
export default {
title: "Components/Button",
component: TextButton,
} as ComponentMeta<typeof TextButton>
const Template: ComponentStory<typeof TextButton> = (args) => <TextButton {...args} />;
@Sanchithasharma
Sanchithasharma / TextButton.stories.tsx
Last active October 28, 2022 12:11
Basic story for the button component
import TextButton from "./TextButton"
import { ComponentMeta, ComponentStory} from "@storybook/react"
export default {
title: "Components/Button",
component: TextButton,
} as ComponentMeta<typeof TextButton>
export const Submit = () => <TextButton label="Submit"/>
@Sanchithasharma
Sanchithasharma / TextButton.tsx
Created October 28, 2022 12:02
Build MUI button component first
import Button from '@mui/material/Button';
type ButtonProps = {
label: string
}
function TextButton({label}: ButtonProps) {
return (
<>
<Button variant="contained">{label}</Button>
@Sanchithasharma
Sanchithasharma / index.js
Created January 13, 2022 16:53
Diff Two Arrays
// Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
// Note: You can return the array with its elements in any order.
function diffArray(arr1, arr2) {
const newArr = [];
filter(arr1, arr2, newArr)
filter(arr2, arr1, newArr)
return newArr;
}
@Sanchithasharma
Sanchithasharma / repeatStr.js
Created January 3, 2022 07:40
Repeat a String Repeat a String
function repeatStringNumTimes(str, num) {
if (num === 0 || Math.sign(num) === -1) {
return ""
}
let arr = [str]
let i = 1
while (i< num) {
arr.push(str)
@Sanchithasharma
Sanchithasharma / lastString.js
Created January 3, 2022 07:25
Confirm the Ending: Check if a string (first argument, str) ends with the given target string (second argument, target).
function confirmEnding(str, target) {
let targetLength = target.length
let strLength = str.length
return target === str.substring(strLength - targetLength);
}
confirmEnding("Bastian", "n");
@Sanchithasharma
Sanchithasharma / largestArray.js
Created January 3, 2022 07:18
Return Largest Numbers in Arrays
function largestOfFour(arr) {
let largestArr = []
for (let el of arr) {
largestArr.push(Math.max(...el))
}
return largestArr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@Sanchithasharma
Sanchithasharma / reverseString.js
Created January 2, 2022 06:52
Reverse string in JavaScript (convert string to array, reverse and join it)
function reverseString(str) {
return str.split('').reverse().join('');
}
reverseString("hello");
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.image {
width: 100%;
height: auto;
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
display: flex;
flex-direction: column;