Skip to content

feat: add solution excercise 001 sorted-order #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
feat: code shows the sorted items of an array of integers, showing ev…
…ery item on a different line
  • Loading branch information
rosariospalla committed Sep 27, 2023
commit 2ab94e137635323898ad650cd6a43671a6623f1e
18 changes: 18 additions & 0 deletions projects/001-sorted-order/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const prompt = require('prompt-sync')({sigint: true});

const array = [];
for (let i = 0; true; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it would have been better to use a while loop rather than an infinite for loop.

const number = Number( prompt("Numero: => ") );

if (number === 0) {
break;
}

array[i] = number;
}

array.sort(function(p1, p2){return p1 - p2});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


for (const number of array) {
console.log(number);
}