Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Соломеина Анастасия #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 101 additions & 2 deletions getPokerHand.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,109 @@
* @param {Array} dice пять костей, для которых нужно определить комбинацию
* @returns {String} название комбинации
*/

function getPokerHand(dice) {
// Напишите ваш замечательный код здесь
if(isPoker(dice))
return 'Покер';
count = getCount(dice)
if(isCare(count))
return 'Каре';
if(isFullHouse(count))
return 'Фулл хаус';
if(isTriple(count))
return 'Тройка';
countOfPairs = getCountOfPairs(count);
//WSH.Echo('countOfPairs = ' + countOfPairs)
if(isTwoPairs(countOfPairs))
return 'Две пары';
if(isPair(countOfPairs))
return 'Пара';
return 'Наивысшее очко';
}

function getCount(dice){
count = new Array(6);
for(i = 0; i < count.length; i++){
count[i] = 0;
}

for(i = 0; i < 5; i++){
switch(dice[i]){
case '1':
count[0]++;
break;
case '2':
count[1]++;
break;
case '3':
count[2]++;
break;
case '4':
count[3]++;
break;
case '5':
count[4]++;
break;
case '6':
count[5]++;
break;
}
}
//WSH.Echo('count ' + count)
return count;
}

function isPoker(dice) {
oneDice = dice[0];
count = 1;
for(i = 1; i < 5; i++) {
if(dice[i] == oneDice)
count++;
}
if(count == 5)
return true;
return false;
}

function isCare(count){
if(count[0] == 4 || count[1] == 4 || count[2] == 4 || count[3] == 4 || count[4] == 4 || count[5] == 4){
return true
}
return false
}

function isFullHouse(count){
if((count[0] == 3 || count[1] == 3 || count[2] == 3 || count[3] == 3 || count[4] == 3 || count[5] == 3) && (count[0] == 2 || count[1] == 2 || count[2] == 2 || count[3] == 2 || count[4] == 2 || count[5] == 2)){
return true;
return false;
}
}

function isTriple(count){
if(count[0] == 3 || count[1] == 3 || count[2] == 3 || count[3] == 3 || count[4] == 3 || count[5] == 3)
return true;
return false;
}

function getCountOfPairs(count){
countOfPairs = 0;
for(i = 0; i < count.length; i++){
if(count[i] == 2)
countOfPairs++;
}
return countOfPairs;
}

function isTwoPairs(count){
if(count == 2)
return true;
return false;
}

return 'Покер';
function isPair(count){
if(count == 1)
return true;
return false;
}

module.exports = getPokerHand;
31 changes: 30 additions & 1 deletion tests/getPokerHand-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,34 @@ describe('getPokerHand', () => {
assert.equal(actual, 'Покер');
});

// Напишите тесты на ваш замечательный код здесь
it('should return `Каре` for [1, 1, 1, 1, 2]', () => {
const actual = getPokerHand([1, 1, 1, 1, 2]);

assert.equal(actual, 'Каре');
});
it('should return `Фулл хаус` for [1, 1, 1, 2, 2]', () => {
const actual = getPokerHand([1, 1, 1, 2, 2]);

assert.equal(actual, 'Фулл хаус');
});
it('should return `Тройка` for [1, 1, 1, 2, 3]', () => {
const actual = getPokerHand([1, 1, 1, 2, 3]);

assert.equal(actual, 'Тройка');
});
it('should return `Две пары` for [1, 1, 2, 2, 3]', () => {
const actual = getPokerHand([1, 1, 2, 2, 3]);

assert.equal(actual, 'Две пары');
});
it('should return `Пара` for [1, 1, 2, 3, 4]', () => {
const actual = getPokerHand([1, 1, 2, 3, 4]);

assert.equal(actual, 'Пара');
});
it('should return `Наивысшее очко` for [1, 2, 3, 4, 5]', () => {
const actual = getPokerHand([1, 2, 3, 4, 5]);

assert.equal(actual, 'Наивысшее очко');
});
});