Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
Intentando crear una barra de búsqueda simple basada en palabras clave en Javascript (Twine)

Estoy tratando de crear una función de búsqueda simple basada en palabras clave en una historia de Twine usando Javascript. Tengo algo funcional usando esta guía, pero estoy tratando de modificarlo ligeramente. Me gustaría que la búsqueda arrojara todas las coincidencias, en lugar de solo la más alta, o al menos las 5 coincidencias más altas. Puede alguien ayudarme con esto? Desafortunadamente, no estoy muy familiarizado con Javascript, por lo que tratar de averiguar qué cambiar y luego a qué cambiarlo ha sido muy difícil.

 window.SearchTerm = window.SearchTerm || function (h, descr, kw) { 'use strict'; if (this instanceof SearchTerm) { this.handle = h; this.description = descr; this.keywords = kw; } else { return new SearchTerm(h, descr, kw); } }; SearchTerm.add = function (h, descr, kw) { termList.push(new SearchTerm(h, descr, kw)); }; SearchTerm.prototype = { compare : function (stringArray) { var term = this; var matches = (function () { var ret = 0; stringArray.forEach( function (str) { if (term.keywords.includes(str)) { ret++; } }); return ret; }()); return matches; }, constructor : window.SearchTerm }; $(document).on('change', 'input[name=search-box]', function (e) { var string = $(this).val(), matches = [], i, n = -1, highest = 0, content; string = string.replace(/[^A-Za-z0-9\s]/, ' '); string = string.replace(/[\s\s+]/, ' '); string = string.trim(); string = string.split(' '); termList.forEach( function (term) { matches.push(term.compare(string)); }); for (i = 0; i < matches.length; i++) { if (matches[i] > n) { n = matches[i]; highest = i; } } if (n <= 0) { content = ''; } else { content = termList[highest].handle + ': ' + termList[highest].description; } $('#output') .empty() .append(content); }); // add your search terms here... SearchTerm.add('Test', '#000', ['test', 'testing']); SearchTerm.add('Test', '#001', ['test', 'testing']); SearchTerm.add('Test', '#002', ['test', 'testing']); // etc.
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda