Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Generar una lista de 1000 números aleatorios entre 1 y 10 y luego contar la cantidad de sietes eliminados

Tengo un proyecto escolar en el que estoy trabajando y realmente estoy luchando para resolverlo.

El proyecto es generar una lista de 1000 números aleatorios entre 1 y 10 y luego eliminar cada instancia de 7 en esta lista. Pero la parte complicada es que se supone que debemos contar la cantidad de 7 eliminados e imprimir esto en la consola...

¿Algunas ideas?

Este no es mi código y es algo con lo que estoy jugando, pero esto es lo que obtuve hasta ahora.

 <!-- Document Required Information --> <!doctype html> <!-- Language & Input Types --> <html lang="no"> <meta charset="utf-8"> <!-- utf-8 gjør at vi kan bruke æ, ø og å --> <head> <title> Oppgave 3 Prøve 3D - 3F - Julian </title> </head> <body> <script> function getRandomExcept(min, max, except) { except.sort(function(a, b) { return a - b; }); var random = Math.floor(Math.random() * (max - min + 1 - except.length)) + min; var i; for (i = 0; i < except.length; i++) { if (except[i] > random) { break; } random++; } return random; } (function(min, max, except) { var iterations = 1000; var i; var random; var results = {}; for (i = 0; i < iterations; i++) { random = getRandomExcept(min, max, except); results[random] = (results[random] || 0) + 1; } for (random in results) { console.log("Antall 7 Fjernet " + except.length + " Tall: " + random + ", Antall: " + results[random] + ", sjanse: " + results[random] * 100 / iterations + "%"); } })(1, 10, [7]); </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esta es una solución sencilla:

 // Start with an empty array let numbers = []; // Do a for loop where you generate your 1000 numbers for(let i = 0; i < 1000; ++i) { // Math.random() return a floating number from 0 to 1 (exclusive), if you multiply it by 10 // you get a floating number between 0 and 10 (exclusive). Math.floor() cuts the decimal part // giving you an integer number between 0 and 9, so you add 1 to get a number between 1 and 10 numbers.push(Math.floor(Math.random() * 10) + 1); } // You can use filter to remove the sevens numbers = numbers.filter(el => el !== 7); // Then you can just compare the length of the array const removed = 1000 - numbers.length; console.log(removed);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!