Skip to content

Instantly share code, notes, and snippets.

@borgeslt
borgeslt / SimpleDemoGA.js
Last active January 22, 2020 11:06
A Simple Genetic Algorithms in Javascript
/*
Based on the Vijini Mallawaarachchi's article in Towards Data Science
https://towardsdatascience.com/introduction-to-genetic-algorithms-including-example-code-e396e98d8bf3
*/
"strict mode"
function Individual(numOfGenes) {
const _genes = Array(numOfGenes).fill(0).map(i => Math.floor(Math.random() * 1000 % 2));
let _fitness = 0;
@borgeslt
borgeslt / ArrayShuffleExtension.js
Last active February 3, 2020 01:28
Shuffling an array in Javascript
Array.prototype.shuffle = function () {
return this.map(item => {
return {
index: Math.random(),
value: item
}
})
.sort((item1, item2) => item1.index - item2.index)
.map(item => item.value)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.