Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Ember from 'ember';
- function shuffle(array) {
- var currentIndex = array.length;
- var temporaryValue;
- var randomIndex;
- // While there remain elements to shuffle...
- while (0 !== currentIndex) {
- // Pick a remaining element...
- randomIndex = Math.floor(Math.random() * currentIndex);
- currentIndex -= 1;
- // And swap it with the current element.
- temporaryValue = array[currentIndex];
- array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
- }
- return array;
- }
- export default Ember.Controller.extend({
- taskData: [],
- personData: [],
- taskIn: ' ',
- personIn: ' ',
- actions: {
- saveTask() {
- const task = this.get("taskIn");
- this.taskData.push(task);
- },
- savePerson()
- {
- const person = this.get("personIn");
- this.personData.push(person);
- },
- print(){
- var taskString;
- //this.taskData.remove(0);
- for(var i = 0; i < this.taskData.length; i++)
- {
- taskString = taskString + this.taskData[i];
- }
- alert(taskString);
- //alert(this.personData);
- },
- //algorithm to match up tasks with people
- assign(){
- let newTaskD = shuffle(this.taskData);
- let newPersonD = shuffle(this.personData);
- var out = '';
- if(newTaskD.length === newPersonD.length){ //3
- for(var i = 0; i <= newPersonD.length; i++){
- out += " " + newPersonD[i] + "" + "->" + "" + newTaskD[i] + "\r";
- }
- }
- if(newTaskD.length > newPersonD.length){ //2
- if(newTaskD.length % newPersonD.length === 0){
- var num = newTaskD / newPersonD;
- for()
- }
- var personCount = 0;
- for(var j = 0; j < newTaskD.length; j++){
- if(personCount != newPersonD.length){
- out += " " + newPersonD[personCount];
- }
- personCount++;
- out += " " + "->" + " " + newTaskD[j] + "\r";
- }
- }
- if(newPersonD.length > newTaskD.length){ //3
- }
- alert(out);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement