-
Notifications
You must be signed in to change notification settings - Fork 33
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
Бёрдов Дмитрий #36
base: master
Are you sure you want to change the base?
Бёрдов Дмитрий #36
Changes from 6 commits
dfbcfd2
32b7cdf
d4002e6
d38e02f
5dc8d6f
59924fa
26235b2
fb4b836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,96 @@ | |
* @param {Array} dice пять костей, для которых нужно определить комбинацию | ||
* @returns {String} название комбинации | ||
*/ | ||
|
||
|
||
function getPokerHand(dice) { | ||
// Напишите ваш замечательный код здесь | ||
|
||
return 'Покер'; | ||
try { | ||
|
||
dice.sort(); | ||
|
||
} | ||
|
||
catch (err) { | ||
|
||
res = ('Не массив'); | ||
return res; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ошибку надо не возвращать throw new Error('Не массив'); |
||
|
||
} | ||
|
||
if (dice.length<5) { | ||
res = ('Элементов меньше 5-ти') | ||
return res; | ||
} | ||
|
||
if (dice.length>5) { | ||
res = ('Элементов больше 5-ти') | ||
return 'Элементов больше 5-ти'; | ||
} | ||
|
||
|
||
var num = [1,0,0,0,0]; | ||
|
||
j = 0; | ||
for(var i = 1; i<5; i++){ | ||
if ((isNaN(dice[i])) || (isNaN(dice[j]))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А можно ограничиться только одной проверкой? |
||
return 'Массив содержит элемент, не являющийся числом'; | ||
} | ||
if ((dice[i]>6) || (dice[j]>6)) { | ||
return 'Массив содержит элемент, больший 6'; | ||
} | ||
if ((dice[i]<1) || (dice[j]<1)) { | ||
return 'Массив содержит элемент, меньший 1'; | ||
} | ||
if (dice[i]!=dice[j]){ | ||
j=i; | ||
} | ||
num[j]++; | ||
} | ||
|
||
|
||
|
||
|
||
max1 = -1; | ||
max2 = -1; | ||
|
||
for(var i = 0; i<5; i++){ | ||
if (num[i]>max1){ | ||
max1=num[i]; | ||
num[i]=-1; | ||
} | ||
} | ||
|
||
for(var i = 0; i<5; i++) { | ||
if (num[i]>max2){ | ||
max2=num[i]; | ||
num[i]=-1; | ||
} | ||
} | ||
|
||
var res = 'Покер'; | ||
switch (max1) { | ||
case 5: res = 'Покер'; break; | ||
case 4: res = 'Каре'; break; | ||
case 3:{ | ||
switch (max2) { | ||
case 2: res = 'Фулл хаус'; break; | ||
case 1: res = 'Тройка'; break; | ||
} | ||
break; | ||
} | ||
case 2:{ | ||
switch (max2) { | ||
case 2: res = 'Две пары'; break; | ||
case 1: res = 'Пара'; break; | ||
} | ||
break; | ||
} | ||
case 1: res = 'Наивысшее очко'; break; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
module.exports = getPokerHand; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,110 @@ describe('getPokerHand', () => { | |
const actual = getPokerHand([1, 1, 1, 1, 1]); | ||
|
||
assert.equal(actual, 'Покер'); | ||
}); | ||
}) | ||
}); | ||
|
||
|
||
describe('getPokerHand', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нужно объявить один
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это замечание всё ещё актуально |
||
it('should return `Каре` for [4, 1, 1, 1, 1]', () => { | ||
const actual = getPokerHand([4, 1, 1, 1, 1]); | ||
|
||
assert.equal(actual, 'Каре'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Фулл хаус` for [1, 1, 1, 2, 2]', () => { | ||
const actual = getPokerHand([1, 1, 1, 2, 2]); | ||
|
||
assert.equal(actual, 'Фулл хаус'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Тройка` for [1, 1, 1, 5, 6]', () => { | ||
const actual = getPokerHand([1, 1, 1, 5, 6]); | ||
|
||
assert.equal(actual, 'Тройка'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Две пары` for [1, 1, 2, 3, 3]', () => { | ||
const actual = getPokerHand([1, 1, 2, 3, 3]); | ||
|
||
assert.equal(actual, 'Две пары'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Пара` for [1, 1, 4, 5, 6]', () => { | ||
const actual = getPokerHand([1, 1, 4, 5, 6]); | ||
|
||
assert.equal(actual, 'Пара'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Наивысшее очко` for [5, 4, 3, 2, 1]', () => { | ||
const actual = getPokerHand([5, 4, 3, 2, 1]); | ||
|
||
assert.equal(actual, 'Наивысшее очко'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Не массив` for 5', () => { | ||
const actual = getPokerHand(5); | ||
|
||
assert.equal(actual, 'Не массив'); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Попробуй воспользоваться |
||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Элементов меньше 5-ти` for [1, 1, 4, 5]', () => { | ||
const actual = getPokerHand([1, 1, 4, 5]); | ||
|
||
assert.equal(actual, 'Элементов меньше 5-ти'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Элементов больше 5-ти` for [5, 2, 3, 5, 1, 1, 5]', () => { | ||
const actual = getPokerHand([5, 2, 3, 5, 1, 1, 5]); | ||
|
||
assert.equal(actual, 'Элементов больше 5-ти'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Не массив` for ', () => { | ||
const actual = getPokerHand(); | ||
|
||
assert.equal(actual, 'Не массив'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Массив содержит элемент, не являющийся числом` for ["a", "b", "c", "d", "e"]', () => { | ||
const actual = getPokerHand(["a", "b", "c", "d", "e"]); | ||
|
||
assert.equal(actual, 'Массив содержит элемент, не являющийся числом'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Массив содержит элемент, больший 6` for [1, 2, 3, 4, 7]', () => { | ||
const actual = getPokerHand([1, 2, 3, 4, 7]); | ||
|
||
assert.equal(actual, 'Массив содержит элемент, больший 6'); | ||
}) | ||
}); | ||
|
||
describe('getPokerHand', () => { | ||
it('should return `Массив содержит элемент, меньший 1` for [0, 2, 3, 4, 2]', () => { | ||
const actual = getPokerHand([0, 2, 3, 4, 2]); | ||
|
||
// Напишите тесты на ваш замечательный код здесь | ||
assert.equal(actual, 'Массив содержит элемент, меньший 1'); | ||
}) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Проверить является ли переменная массивом можно оператором
Array.isArray(dice)