Skip to content

Instantly share code, notes, and snippets.

@screeny05
Created December 1, 2017 10:45
Show Gist options
  • Save screeny05/451ae4eac7d0b4160703ead313a9163e to your computer and use it in GitHub Desktop.
Save screeny05/451ae4eac7d0b4160703ead313a9163e to your computer and use it in GitHub Desktop.
Express App zum Wichtel-Ziehen
const express = require('express');
const names = [
'arved',
'ahmad',
'sebastian',
'marcel'
];
const randomIndexFromArray = array => {
return Math.floor(Math.random() * names.length);
};
const getNameAndRemove = iam => {
let nameIndex;
do {
nameIndex = randomIndexFromArray(names);
} while(names[nameIndex] === iam);
const name = names.splice(nameIndex, 1)[0];
return name;
};
const app = express();
app.get('/get/:iam', (req, res) => {
const name = getNameAndRemove(req.params.iam);
if(!name){
return res.send('namelist empty');
}
res.send('your name: ' + name);
console.log('names remaining in list', names.length);
});
app.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment