Created
December 1, 2017 10:45
-
-
Save screeny05/451ae4eac7d0b4160703ead313a9163e to your computer and use it in GitHub Desktop.
Express App zum Wichtel-Ziehen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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