Fixes line endings
This commit is contained in:
parent
9855ba6fe7
commit
02d32ae902
2 changed files with 178 additions and 178 deletions
156
SecretSanta.js
156
SecretSanta.js
|
@ -1,78 +1,78 @@
|
|||
var SecretSanta = function () {
|
||||
|
||||
this.names = [];
|
||||
|
||||
this.blacklists = Object.create( null );
|
||||
};
|
||||
|
||||
|
||||
SecretSanta.prototype.add = function ( name ) {
|
||||
|
||||
if ( this.names.indexOf( name ) !== -1 )
|
||||
throw new Error( 'Cannot redefine ' + name );
|
||||
|
||||
this.names.push( name );
|
||||
|
||||
var subapi = { };
|
||||
|
||||
subapi.blacklist = function ( other ) {
|
||||
|
||||
if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||
this.blacklists[ name ] = [];
|
||||
|
||||
if ( this.blacklists[ name ].indexOf( other ) === -1 )
|
||||
this.blacklists[ name ].push( other );
|
||||
|
||||
return subapi;
|
||||
|
||||
}.bind( this );
|
||||
|
||||
return subapi;
|
||||
|
||||
};
|
||||
|
||||
SecretSanta.prototype.generate = function () {
|
||||
|
||||
var pairings = Object.create( null );
|
||||
var candidatePairings = Object.create( null );
|
||||
|
||||
this.names.forEach( function ( name ) {
|
||||
|
||||
var candidates = _.difference( this.names, name );
|
||||
|
||||
if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||
candidates = _.difference( candidates, this.blacklists[ name ] );
|
||||
|
||||
candidatePairings[ name ] = candidates;
|
||||
|
||||
}, this );
|
||||
|
||||
var findNextGifter = function () {
|
||||
|
||||
var names = Object.keys( candidatePairings );
|
||||
|
||||
var minCandidateCount = _.min( names.map( function ( name ) { return candidatePairings[ name ].length; } ) );
|
||||
var potentialGifters = names.filter( function ( name ) { return candidatePairings[ name ].length === minCandidateCount; } );
|
||||
|
||||
return _.sample( potentialGifters );
|
||||
|
||||
};
|
||||
|
||||
while ( Object.keys( candidatePairings ).length > 0 ) {
|
||||
|
||||
var name = findNextGifter();
|
||||
|
||||
var pairing = _.sample( candidatePairings[ name ] );
|
||||
delete candidatePairings[ name ];
|
||||
|
||||
Object.keys( candidatePairings ).forEach( function ( name ) {
|
||||
candidatePairings[ name ] = _.without( candidatePairings[ name ], pairing );
|
||||
} );
|
||||
|
||||
pairings[ name ] = pairing;
|
||||
|
||||
}
|
||||
|
||||
return pairings;
|
||||
|
||||
};
|
||||
var SecretSanta = function () {
|
||||
|
||||
this.names = [];
|
||||
|
||||
this.blacklists = Object.create( null );
|
||||
};
|
||||
|
||||
|
||||
SecretSanta.prototype.add = function ( name ) {
|
||||
|
||||
if ( this.names.indexOf( name ) !== -1 )
|
||||
throw new Error( 'Cannot redefine ' + name );
|
||||
|
||||
this.names.push( name );
|
||||
|
||||
var subapi = { };
|
||||
|
||||
subapi.blacklist = function ( other ) {
|
||||
|
||||
if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||
this.blacklists[ name ] = [];
|
||||
|
||||
if ( this.blacklists[ name ].indexOf( other ) === -1 )
|
||||
this.blacklists[ name ].push( other );
|
||||
|
||||
return subapi;
|
||||
|
||||
}.bind( this );
|
||||
|
||||
return subapi;
|
||||
|
||||
};
|
||||
|
||||
SecretSanta.prototype.generate = function () {
|
||||
|
||||
var pairings = Object.create( null );
|
||||
var candidatePairings = Object.create( null );
|
||||
|
||||
this.names.forEach( function ( name ) {
|
||||
|
||||
var candidates = _.difference( this.names, name );
|
||||
|
||||
if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||
candidates = _.difference( candidates, this.blacklists[ name ] );
|
||||
|
||||
candidatePairings[ name ] = candidates;
|
||||
|
||||
}, this );
|
||||
|
||||
var findNextGifter = function () {
|
||||
|
||||
var names = Object.keys( candidatePairings );
|
||||
|
||||
var minCandidateCount = _.min( names.map( function ( name ) { return candidatePairings[ name ].length; } ) );
|
||||
var potentialGifters = names.filter( function ( name ) { return candidatePairings[ name ].length === minCandidateCount; } );
|
||||
|
||||
return _.sample( potentialGifters );
|
||||
|
||||
};
|
||||
|
||||
while ( Object.keys( candidatePairings ).length > 0 ) {
|
||||
|
||||
var name = findNextGifter();
|
||||
|
||||
var pairing = _.sample( candidatePairings[ name ] );
|
||||
delete candidatePairings[ name ];
|
||||
|
||||
Object.keys( candidatePairings ).forEach( function ( name ) {
|
||||
candidatePairings[ name ] = _.without( candidatePairings[ name ], pairing );
|
||||
} );
|
||||
|
||||
pairings[ name ] = pairing;
|
||||
|
||||
}
|
||||
|
||||
return pairings;
|
||||
|
||||
};
|
||||
|
|
200
pairing.html
200
pairing.html
|
@ -1,100 +1,100 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<title>Secret Santa Pairing</title>
|
||||
|
||||
<script src="vendors/Lodash-3.10.1.js"></script>
|
||||
<script src="vendors/Cryptojs.aes-3.1.2.js"></script>
|
||||
|
||||
<style>
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body, .main {
|
||||
margin: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image: url(assets/santa.png);
|
||||
background-position: bottom right;
|
||||
background-repeat: no-repeat;
|
||||
|
||||
font-family: 'Comic Sans MS';
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin: auto;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.pairing {
|
||||
font-size: 90px;
|
||||
}
|
||||
|
||||
.affiliate {
|
||||
display: block;
|
||||
box-sizing: content-box;
|
||||
|
||||
margin-top: 70px;
|
||||
|
||||
border: 10px solid #0CB50C;
|
||||
border-radius: 10px;
|
||||
|
||||
background: rgba(255, 255, 255, .7);
|
||||
}
|
||||
|
||||
.affiliate + .affiliate {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script>1
|
||||
|
||||
var queryString = _.chain( location.search.slice( 1 ).split( /&/g ) )
|
||||
.map( function ( item ) { if ( item ) return item.split( /=/ ).map( function ( str ) { return decodeURIComponent( str ); } ); } )
|
||||
.compact().object().value();
|
||||
|
||||
var name = queryString.name;
|
||||
var pairing = CryptoJS.AES.decrypt( queryString.pairing, queryString.key ).toString(CryptoJS.enc.Utf8);
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="main">
|
||||
|
||||
<div class="content">
|
||||
<h3 class="title">Hi <script>document.write(name)</script>! You've been paired with</h3>
|
||||
<h1 class="pairing"><script>document.write(pairing)</script></h1>
|
||||
<h3 class="title">Good luck!</h3>
|
||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=jeuxetjouets&banner=0HS03ACZ89HPK7F4F5G2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=books&banner=10DQAXJ7D1D2VTXMR682&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<title>Secret Santa Pairing</title>
|
||||
|
||||
<script src="vendors/Lodash-3.10.1.js"></script>
|
||||
<script src="vendors/Cryptojs.aes-3.1.2.js"></script>
|
||||
|
||||
<style>
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body, .main {
|
||||
margin: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image: url(assets/santa.png);
|
||||
background-position: bottom right;
|
||||
background-repeat: no-repeat;
|
||||
|
||||
font-family: 'Comic Sans MS';
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin: auto;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.pairing {
|
||||
font-size: 90px;
|
||||
}
|
||||
|
||||
.affiliate {
|
||||
display: block;
|
||||
box-sizing: content-box;
|
||||
|
||||
margin-top: 70px;
|
||||
|
||||
border: 10px solid #0CB50C;
|
||||
border-radius: 10px;
|
||||
|
||||
background: rgba(255, 255, 255, .7);
|
||||
}
|
||||
|
||||
.affiliate + .affiliate {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script>1
|
||||
|
||||
var queryString = _.chain( location.search.slice( 1 ).split( /&/g ) )
|
||||
.map( function ( item ) { if ( item ) return item.split( /=/ ).map( function ( str ) { return decodeURIComponent( str ); } ); } )
|
||||
.compact().object().value();
|
||||
|
||||
var name = queryString.name;
|
||||
var pairing = CryptoJS.AES.decrypt( queryString.pairing, queryString.key ).toString(CryptoJS.enc.Utf8);
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="main">
|
||||
|
||||
<div class="content">
|
||||
<h3 class="title">Hi <script>document.write(name)</script>! You've been paired with</h3>
|
||||
<h1 class="pairing"><script>document.write(pairing)</script></h1>
|
||||
<h3 class="title">Good luck!</h3>
|
||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=jeuxetjouets&banner=0HS03ACZ89HPK7F4F5G2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=books&banner=10DQAXJ7D1D2VTXMR682&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue