<commit_before>// start loading sounds without waiting for any event
var sounds = (function(){
	function makeNamedSounds(names, nameToUrlsTransformer) {
		var sounds = {};
		names.forEach(function(name) {
			sounds[name] = new Howl({
				urls: nameToUrlsTransformer(name),
			});
		});
		return sounds;
	}
	
	var soundNames = ["tick1", "tock1", "tick2", "tock2"];
	return makeNamedSounds(soundNames, function(name) {
		return ["sounds/wav/" + name + ".wav", "sounds/mp3/" + name + ".mp3"];
	});
})();

function playTickSound() {
	playSound(_.sample(["tick1", "tick2"]));
}
function playTockSound() {
	playSound(_.sample(["tock1", "tock2"]));
}
function playSound(name) {
	var sound = sounds[name];
	sound.stop();
	sound.play();
}

function trueWithProbability(probability) {
	return (Math.random() < probability);
}<commit_msg>Refactor sound loading and referencing<commit_after>// global-scope functions used:
var _, jQuery, $, Howl;


var soundNamesByType = {
	ticks: ["tick1", "tick2"],
	tocks: ["tock1", "tock2"],
};
var allSoundNames = (soundNamesByType.ticks).concat(soundNamesByType.tocks);

// objectByMappingKeys: converts an array of string keys `['a', 'b']`
// to a mapping object `{a: mapCallback('a'), b: mapCallback('b')}`
function objectByMappingKeys(keysArray, mapCallback) {
	var object = {};
	keysArray.forEach(function(key) {
		object[key] = mapCallback(key);
	});
	return object;
}

function initializeSounds(soundNames) {
	return objectByMappingKeys(soundNames, function(name) {
		var urls = urlsForSoundName(name);
		return new Howl({urls: urls});
	});
	
	function urlsForSoundName(name) {
		return ["sounds/wav/"+name+".wav", "sounds/mp3/"+name+".mp3"];
	}
}

// start loading sounds without waiting for any event
var sounds = initializeSounds(allSoundNames);


function playTickSound() {
	playNamedSound(_.sample(soundNamesByType.ticks));
}
function playTockSound() {
	playNamedSound(_.sample(soundNamesByType.tocks));
}
function playNamedSound(name) {
	var sound = sounds[name];
	sound.stop();
	sound.play();
}

function trueWithProbability(probability) {
	return (Math.random() < probability);
}

{'fraction_non_alphanumeric': 0.1649387370405278, 'fraction_numerical': 0.007540056550424128, 'mean_word_length': 5.512269938650307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '456849', 'n_tokens_mistral': 745, 'n_tokens_neox': 716, 'n_words': 156}