feat: add logic
input string & target, turn into array object, sort array, output message
This commit is contained in:
parent
3029c98cd0
commit
d45a1c229e
4 changed files with 47 additions and 198 deletions
11
index.js
11
index.js
|
|
@ -1,3 +1,12 @@
|
|||
import { input } from '@inquirer/prompts';
|
||||
|
||||
const answer = await input({ message: 'Enter your name' });
|
||||
const answer = await input({ message: 'Enter an array of numbers separated by commas:' });
|
||||
|
||||
const array = answer.split(',').filter(Boolean).map(Number).sort((a, b) => a - b);
|
||||
|
||||
const target = await input({ message: 'Enter a target number:' });
|
||||
|
||||
const index = array.findIndex((num) => num == target);
|
||||
|
||||
console.log('Sorted array:', array);
|
||||
console.log(index === -1 ? 'Target number not found' : `Target number found at index ${index}`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue