/**
 * models/drawModel.js
 * Module that defines winning numbers in the draw
 *
 * @return	{function} Model constructor extended from Bacbone.Model
 * @author  Ben on 18/Jul/2012
 */

define([
	'jquery',
	'backbone'
], function($) {

return Backbone.Model.extend({

	// Manually set prize and winning numbers
	setData: function(data) {
		var index = 0,
			numberList = {},
			prizeNameOfID = {};

		// map the prize id, prize name, and winning numbers
		$.each(data.prizes, function(key, value) {
			prizeNameOfID[index + 'thPrize'] = key;
			numberList[index + 'thPrize'] = value;
			index += 1;
		});

		this.clear({silent: true});
		this.set({
			months: data.months.replace(/0(?=[1-9])/g, ""),
			numberList: numberList,
			prizeNameOfID: prizeNameOfID
		});

		this.sortDataByType();
		this.createNumberNameMapping();
	},

	// Helper function: sort numbers into 2 categories
	sortDataByType: function() {
		var self = this,
			numberList = self.get('numberList'),
			prizeNameOfID = self.get('prizeNameOfID');

		this.set({
			// numbers that need every digit matching
			matchAll:
				$.map(numberList, function(numbers, id) {
					if ( prizeNameOfID[id] === "特別獎" || prizeNameOfID[id] === "特獎" )
						return numbers;
				}),
			// numbers that need at least three ending digits matching
			matchThree:
				$.map(numberList, function(numbers, id) {
					if ( prizeNameOfID[id] !== "特別獎" && prizeNameOfID[id] !== "特獎" )
						return numbers;
				})
		});
	},

	// Helper function: create prize number-name mapping
	createNumberNameMapping: function() {
		var numbers = $.map(this.get('numberList'), function(value, id) { return value; });
		var self = this,
			prizeNameOfID = this.get('prizeNameOfID'),
			prizeNameOfNumber = {};

		$.each(this.get('numberList'), function(id, numbers) {
			$.each(numbers, function(i, number) {
				prizeNameOfNumber[number] = prizeNameOfID[id];
			});
		});
		this.set('prizeNameOfNumber', prizeNameOfNumber);
	}
});

});
/**
 * models/drawModel.js
 * Module that defines winning numbers in a draw
 *
 * @return	{function} Model constructor extended from Bacbone.Model
 * @author  Ben on 18/Jul/2012
 */

define([
	'jquery',
	'backbone'
], function($) {

return Backbone.Model.extend({

	// Manually set prize and winning numbers
	setData: function(data) {
		var prizeNumbers = data.prizes;

		this.clear({silent: true});
		this.set({
			months: data.months.replace(/0(?=[1-9])/g, ""),
			prizeNumbers: prizeNumbers
		});

		this.sortDataByType();
		this.createNumberNameMapping();
	},

	// Helper function: sort numbers into 2 categories
	sortDataByType: function() {
		var self = this,
			prizeNumbers = this.get('prizeNumbers');

		this.set({
			// numbers that need every digit matching
			matchAll:
				$.map(prizeNumbers, function(numbers, name) {
					if (name === "特別獎" || name === "特獎")
						return numbers;
				}),
			// numbers that need at least three ending digits matching
			matchThree:
				$.map(prizeNumbers, function(numbers, name) {
					if (name !== "特別獎" && name !== "特獎")
						return numbers;
				})
		});
	},

	// Helper function: create prize number-name mapping
	createNumberNameMapping: function() {
		var self = this,
			prizeNameOfNumber = {};

		$.each(this.get('prizeNumbers'), function(name, numbers) {
			$.each(numbers, function(index, number) {
				prizeNameOfNumber[number] = name;
			});
		});

		this.set('prizeNameOfNumber', prizeNameOfNumber);
	}
});

});

Replace numberList and prizeNameOfID with prizeNumbers