repl.it
@ThomasS1/

IOC calculator

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function ioc(text, alphabet, caseSensitive) {
	if (caseSensitive == false) {
		text = text.toUpperCase()
		alphabet = alphabet.toUpperCase()
	}
	text = text.split('').filter(c => alphabet.indexOf(c) > -1).join("")
	var l = text.length
	var ioc = 0
	for (let i = 0; i < alphabet.length; i++) {
		a = [...text].filter(k => k === alphabet[i]).length;
		console.log(a)
		ioc += (a/l) * ((a-1)/(l-1))
	}
	return (ioc * alphabet.length)
}
?