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

184
Views
No estoy seguro de por qué este código no funciona. El programa debe buscar a través de esta lista de palabras y eliminar cualquier palabra que incluya la letra A.

Esto se está haciendo en code.org, por alguna razón elimina algunas palabras con la letra A pero no todas, no estoy seguro de por qué no funcionará.

 var wordList = ["abase", "abate", "abbey", "abbot", "abhor", "abide", "abled", "abode", "abort", "about", "above", "abuse", "abyss", "acorn", "acrid", "actor", "acute", "adage", "adapt", "adept", "admin", "admit", "adobe", "adopt", "adore", "adorn", "adult", "affix", "afire", "afoot", "afoul", "after", "bulge", "bulky", "bully", "bunch", "bunny", "burly", "burnt", "burst", "bused", "bushy", "butch", "butte", "buxom", "buyer", "bylaw", "cabal", "cabby", "cabin", "cable", "cacao", "cache", "cacti", "pique", "setup", "seven", "sever", "wrote", "wrung", "wryly", "yacht", "yearn", "yeast", "yield", "young", "youth", "zebra", "zesty", "zonal"]; var wrongLettersList = ["a"]; var unsureLettersList = []; var goodLettersList = []; onEvent("wrongLetterInput", "input", function( ) { appendItem(wrongLettersList, getText("wrongLetterInput")); setProperty("wrongLetterInput","text", ""); setProperty("wrongLetterInput", "placeholder", "Letters inputted: "+wrongLettersList); listFilter(wrongLettersList, unsureLettersList, goodLettersList); }); function listFilter(wrongLetters, unsureLetters, goodLetters) { for(var j = 0; j<wordList.length; j++) { if(wordList[j].includes(wrongLetters[0])){ wordList.splice(j, 1); } } console.log(wordList); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Eso es porque te saltas una palabra una vez que empalmas. La opción fácil, pero no la mejor, es:

 function listFilter(wrongLetters, unsureLetters, goodLetters) { for(var j = 0; j<wordList.length; j++) { if(wordList[j].includes(wrongLetters[0])){ wordList.splice(j, 1); j-=1; // ---> decrement 1 from j so you don't skip a word } } console.log(wordList); }

Pero definitivamente, como se dijo anteriormente, usar el filtro es mucho más fácil y legible.

 return wordList.filter(w => !w.includes(wrongLettersList[0]));
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!