Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Match{
- #inPut = [];
- #outPut = {};
- constructor (...data){
- this.#inPut = [...data];
- if (this.#inPut.length%2 !== 0){
- throw new Error ('Enter even number of names')
- }
- }
- get match () {
- while(this.#inPut.length !== 0){
- let indexfOfkey = Math.floor(this.#inPut.length*Math.random());
- let key = this.#inPut.splice(indexfOfkey,1);
- let indexOfvalue = Math.floor(this.#inPut.length*Math.random());
- let value = this.#inPut.splice(indexOfvalue,1);
- this.#outPut[key] = value
- }
- console.table(this.#outPut);
- }
- }
- const names = new Match('ivo','gosho','mitko','stoyan','nikolay','atanas','martin','ivaylo','krystan','grigoriy')
- names.match
Advertisement
Add Comment
Please, Sign In to add comment