Skip to content

Instantly share code, notes, and snippets.

View Kash2910's full-sized avatar

Mohammed Kashif Siddiqui Kash2910

View GitHub Profile
@Kash2910
Kash2910 / User.js
Created September 24, 2021 22:15
Nested Routes
import React, {useState} from "react";
import {Link, NavLink, Route, Switch, useParams, useRouteMatch} from "react-router-dom";
import UserPosts from "./UserPosts";
import UserProfile from "./UserProfile";
export const User = ({ users = [] }) => {
const [showPosts, setShowPosts] = useState(false)//to show profile and post
const {url} = useRouteMatch()
import "./styles.css";
/*
Add event listeners to the .expand_button buttons
*/
const expandButtonClickHandler = (event) => {
const article = event.target.parentNode.parentNode.parentNode;
const article_body = article.querySelector('.article_body');
const ratings = require("../data/ratings-data");
function ratingExists(req, res, next) {
const ratingId = Number(req.params.ratingId);
const foundRating = ratings.find((rating) => rating.id === ratingId);
if (foundRating === undefined) {
return next({
@Kash2910
Kash2910 / index.js
Last active October 24, 2021 01:34
////////////////////////////
// DO NOT EDIT THIS ARRAY //
////////////////////////////
/*
The contacts array contain the list of contacts for the contact book.
*/
window.contacts = [
{
id: 1,
name: "Leanne Graham",
const service = require("./restaurants.service.js");
const asyncErrorBoundary = require("../errors/asyncErrorBoundary");
async function averageRating(req, res, next) {
const ratingReturned = await service.averageRating();
let {avg: rating} = ratingReturned;
rating = parseFloat(rating)
res.json({ data: {average_rating: rating} });
}
function findAuthorById(authors, id) {
let found = authors.find((author) => author.id === id)
return found
}
function findBookById(books, id) {
let found = books.find((book) => book.id === id)
return found
}
const LinkedList = require("./linkedList");
class Queue {
constructor() {
this.linkedList = new LinkedList();
}
enqueue(value) {
this.linkedList.insert(value);
}
App.js----------------------------
import React, { Fragment } from "react";
import { Link, NavLink, Route, Switch, useParams, useRouteMatch} from 'react-router-dom'
import Header from "./common/Header";
import CardList from "./home/CardList";
import User from "./user/User";
import NotFound from "./common/NotFound"
function printNames (names) {
names.forEach((name) => {
console.log(name);
});
}
function logTreeType (trees){
trees.forEach((tree) => {
console.log (tree.type);
function partitionStudentsByScore(students, score) {
const result = []
const target = []
const excess = []
students.forEach(student => {
student.score <= score ? target.push(student) : excess.push(student)
})
result.push(target, excess)
return result;
}