This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function treeSearch(graph, start, goal, algorithm = "bfs") { | |
const fringe = [{ | |
state: start, | |
parent: null, | |
action: null, | |
pathCost: 0, | |
depth: 0, | |
path: [start] | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}, {}) | |
} | |
/*---------------------------------------------------------------*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************** Write Clipboard *********************/ | |
const text = "Hello World!" | |
navigator.clipboard?.writeText(text).then(() => { | |
alert("Copied!") | |
}) | |
/***************** Read Clipboard (:string)*********************/ |