Skip to content

Instantly share code, notes, and snippets.

View ramezanidev's full-sized avatar
🏠
Working from home

Reza Ramezani ramezanidev

🏠
Working from home
View GitHub Profile
function createIndividual() {
const individual = [...Array(8).keys()];
for (let i = 0; i < 8; i++) {
const r = Math.floor(Math.random() * 8);
[individual[i], individual[r]] = [individual[r], individual[i]];
}
return individual;
}
@ramezanidev
ramezanidev / treeSearch.js
Last active April 21, 2025 04:40
Tree Search JS
function treeSearch(graph, start, goal, algorithm = "bfs") {
const fringe = [{
state: start,
parent: null,
action: null,
pathCost: 0,
depth: 0,
path: [start]
}];
function libraryFine(d1, m1, y1, d2, m2, y2) {
if (y1 <= y2) {
if (y1 < y2) return 0
if (m1 <= m2) {
if (m1 < m2) return 0
if (d1 <= d2) {
return 0
} else return (d1 - d2) * 15
} return (m1 - m2) * 500
} else return 10000;
function repeatedString(s, n) {
const a = s.replace(/[^a]/g, '').length;
let b = Math.floor(n / s.length) * a;
const c = (n % s.length);
if (c) {
b += s.slice(0, c).replace(/[^a]/g, '').length
}
@ramezanidev
ramezanidev / index.js
Last active December 26, 2021 13:23
javascript groupBy method
Array.prototype.groupBy = function (Fun, This) {
return this.reduce((result, item, ...arg) => {
const key = Fun.call(This, item, ...arg);
key in result ? result[key].push(item) : result[key] = [item];
return result
}, {})
}
/*---------------------------------------------------------------*/
@ramezanidev
ramezanidev / index.html
Last active November 16, 2021 05:23
rtl variant tailwindcss
<!DOCTYPE html>
<!--
Each time add the attribute dir="rtl" to the html tag. Classes "rtl:ml-5 rtl:mr-0" are executed
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ramezanidev
ramezanidev / clipboard.js
Last active October 17, 2021 05:44
clipboard js
/***************** Write Clipboard *********************/
const text = "Hello World!"
navigator.clipboard?.writeText(text).then(() => {
alert("Copied!")
})
/***************** Read Clipboard (:string)*********************/