Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function result(command) {
- let commands = {
- upvote: () => this.upvotes++,
- downvote: () => this.downvotes++,
- score: () => {
- let totalVotes = this.upvotes + this.downvotes;
- const numberToAdd = Math.ceil(Math.max(this.upvotes, this.downvotes) * 0.25);
- let reportUpVotes = totalVotes > 50 ? this.upvotes + numberToAdd : this.upvotes;
- let reportDownVotes = totalVotes > 50 ? this.downvotes + numberToAdd : this.downvotes;
- let totalScore = this.upvotes - this.downvotes;
- let majority = this.upvotes / totalVotes > 0.66;
- let rating = '';
- if (totalVotes < 10) {
- rating = 'new';
- } else if (totalScore < 0) {
- rating = 'unpopular';
- }else if (majority) {
- rating = 'hot'
- } else if (reportUpVotes > 100 || reportDownVotes > 100) {
- rating = 'controversial';
- } else {
- rating = 'new';
- }
- return [reportUpVotes, reportDownVotes, totalScore, rating];
- }
- };
- return commands[command]();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement