Skip to content

Instantly share code, notes, and snippets.

View abel-masila's full-sized avatar
⚛️
Shipping code!

Abel Masila abel-masila

⚛️
Shipping code!
View GitHub Profile
function countRectangles(board) {
let count = 0;
let N = board.length;
let M = board[0].length;
for (let r = 0; r < N; r++) {
for (let c = 0; c < M; c++) {
for (let i = r; i < N; i++) {
for (let j = c; j < M; j++) {
let aCount = 0;
@abel-masila
abel-masila / nights.js
Last active March 24, 2023 21:24
hard stuff
function combineCustomNights(customNights) {
const result = [];
let currentRange = null;
customNights.sort((a, b) => new Date(a.date) - new Date(b.date));
customNights.forEach((night) => {
if (!currentRange) {
currentRange = { start: night.date, end: night.date, rooms: { ...night } };
delete currentRange.rooms.date;
function belongsToTriangle(x1, y1, x2, y2, x3, y3, xp, yp, xq, yq) {
// Calculate the length of the sides of the triangle
const lab = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
const lac = Math.sqrt((x3 - x1) ** 2 + (y3 - y1) ** 2);
const lbc = Math.sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2);
// Check if the triangle is non-degenerate
if (lab + lac <= lbc || lab + lbc <= lac || lac + lbc <= lab) {
return "o";
}
function palindromeChecker(s, startindex, endindex, subs) {
let result = '';
for (let i = 0; i < startindex.length; i++) {
let sub = s.substring(startindex[i], endindex[i] + 1);
let count = new Array(26).fill(0);
for (let j = 0; j < sub.length; j++) {
count[sub.charCodeAt(j) - 97]++;
}
let oddCount = 0;
for (let j = 0; j < 26; j++) {
function makePalindrome(s, startindex, endindex, subs) {
let result = "";
for (let i = 0; i < startindex.length; i++) {
let substring = s.substring(startindex[i], endindex[i] + 1);
let count = 0;
let charMap = new Map();
for (let j = 0; j < substring.length; j++) {
charMap.set(substring.charAt(j), charMap.get(substring.charAt(j)) + 1 || 1);
}
for (let [char, freq] of charMap) {
// Value types can be three, value1, value2, value3
const items=[
{
"date": "2023-02-01",
"value1": 1,
"value2": 1
},
{
"date": "2023-02-03",
/* eslint-disable no-unused-expressions */
import React, { useState, useEffect } from "react";
import {
AppBar,
Button,
Card,
Dialog,
DialogActions,
DialogContent,
const handleDBReponse = (response) => {
const appointments = response;
const today = moment().startOf("day"); //start of today 12 am
const initialSchedule = {};
initialSchedule[today.format("YYYY-DD-MM")] = true;
const schedule = !appointments.length
? initialSchedule
: appointments.reduce((currentSchedule, appointment) => {
const { slot_date, slot_time } = appointment;
const dateString = moment(slot_date, "YYYY-DD-MM").format("YYYY-DD-MM");
import React, { useState } from "react";
import axios from "axios";
function AddPosts() {
const [formData, setformData] = useState({
post: "",
title: "",
});
const handleChange = (event) => {
setformData({ ...formData, [event.target.name]: event.target.value });
};
import React, { useState, useEffect } from "react";
import axios from "axios";
function ViewPost(props) {
const [post, setPost] = useState({});
const id = props.match.params.id;
//OR const { id } = props.match.params;
useEffect(() => {
axios
.get(`https://jsonplaceholder.typicode.com/posts/${id}`)
.then((response) => {