-
Notifications
You must be signed in to change notification settings - Fork 538
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
finished #435
base: master
Are you sure you want to change the base?
finished #435
Changes from all commits
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
module.exports = { | ||
extends: '@mate-academy/eslint-config', | ||
env: { | ||
jest: true | ||
jest: true, | ||
}, | ||
rules: { | ||
'no-proto': 0 | ||
'no-proto': 'warn', | ||
}, | ||
plugins: ['jest'] | ||
plugins: ['jest'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,21 @@ name: Test | |
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
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. Consider updating the 'setup-node' action to 'v3' to benefit from the latest features and security updates. |
||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
'use strict'; | ||
import readline from 'node:readline'; | ||
import { generateRandomNumber } from './modules/generateRandomNumber.js'; | ||
import { checkIsValidUserInput } from './modules/checkIsValidUserInput.js'; | ||
import { getBullsAndCows } from './modules/getBullsAndCows.js'; | ||
|
||
// Write your code here | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
const hiddenNumber = generateRandomNumber(); | ||
|
||
const requestANumber = () => { | ||
// console.log(hiddenNumber); | ||
|
||
rl.question('Write your number? ', (userValue) => { | ||
const isValidUserInput = checkIsValidUserInput(userValue); | ||
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. Ensure that the |
||
|
||
if (!isValidUserInput) { | ||
requestANumber(); | ||
|
||
return; | ||
} | ||
|
||
const bullsAndCows = getBullsAndCows(userValue, hiddenNumber); | ||
|
||
if (bullsAndCows.bulls === 4) { | ||
rl.close(); | ||
|
||
return; | ||
} | ||
|
||
requestANumber(); | ||
}); | ||
}; | ||
|
||
requestANumber(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,63 @@ | |
* @param {string} userInput - The user input | ||
* @return {boolean} - True if the user input is valid, false otherwise | ||
*/ | ||
const checkIsUniqueNumbers = (value) => { | ||
const arrayValue = `${value}`.split(''); | ||
// console.log(arrayValue.length); | ||
|
||
if (arrayValue.length !== 4) { | ||
// console.log('(arrayValue.length !== 4)'); | ||
|
||
return false; | ||
} | ||
|
||
if (typeof +value !== 'number') { | ||
// console.log(`(typeof value !== 'number')`); | ||
|
||
return false; | ||
} | ||
|
||
if (arrayValue[0] === '0') { | ||
// console.log(`(arrayValue[0] === '0')`); | ||
|
||
return false; | ||
} | ||
|
||
const arrayValueToCheck = [...arrayValue]; | ||
|
||
for (let i = 0; i < arrayValue.length; i++) { | ||
const numberToCheck = arrayValue[i]; | ||
|
||
arrayValueToCheck.splice(i, 1); | ||
|
||
if (arrayValueToCheck.includes(numberToCheck)) { | ||
// console.log(`arrayValueToCheck.includes(numberToCheck)`); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
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. The |
||
} | ||
}; | ||
|
||
function checkIsValidUserInput(userInput) { | ||
/* Write your code here */ | ||
|
||
const numberedUserInput = +userInput; | ||
|
||
if (userInput.length !== 4) { | ||
return false; | ||
} | ||
|
||
if (typeof numberedUserInput !== 'number' || isNaN(numberedUserInput)) { | ||
return false; | ||
} | ||
|
||
if (+userInput[0] === 0) { | ||
return false; | ||
} | ||
|
||
return checkIsUniqueNumbers(userInput); | ||
} | ||
|
||
module.exports = { | ||
|
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.
Consider using 'actions/setup-node@v3' instead of 'v1' to ensure you are using the latest features and security updates.