Skip to content

Instantly share code, notes, and snippets.

@Albertbol
Albertbol / fitnessLevel.js
Last active March 7, 2021 17:39
Calculate fitness level
const pow = 10
fitnessLevel(randomPhrase) {
let fitnessLevel = 0
for (let i = 0; i < this.phraseToGuess.length; i++) {
// Compare letters
if (this.phraseToGuess[i] === randomPhrase[i]) {
fitnessLevel++
}
}
@Albertbol
Albertbol / generatePopulation.js
Last active March 7, 2021 10:15
Generate population
const phraseToGuess = 'random phrase'
const populationSize = 200
const population = []
// Demo function to pick random latin basic UTF-8 characters
// you can see full table here:
// https://www.w3schools.com/charsets/ref_utf_basic_latin.asp
newChar() {
let c = Math.floor(Math.random() * 59) + 63
if (c === 63) c = 32 // change "?" to " " space
#Stop following command execution if command before failed
set -e
#Remove previous bucket if exists
delete_previous_version_if_exists() {
#We either delete local folder and bucket object or just a bucket
rm -r ./your-choosen-folder &&
gsutil -m rm -r gs://your-production-project/your-choosen-folder ||
gsutil -m rm -r gs://your-production-project/your-choosen-folder
}