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

289
Views
Why does returning a console.log() return undefined?

this is my code, my last console.log return an undefined result, can you help me to understand why?

I don't really understand why this happened but I'm sure that is a really stupid thing

also, this is the input(elem_riga)

00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010
const fs = require("fs");
const input = fs.readFileSync("./demo.txt").toString();
const elem_riga = input.split("\n");

const most_common = (filtro_vincente, index) => {
  for (let i of filtro_vincente) {
    index++;
    const filtro_uno = filtro_vincente.filter((e) => e[index] === "1");
    const filtro_due = filtro_vincente.filter((e) => e[index] === "0");
    filtro_uno.length > filtro_due.length
      ? (filtro_vincente = filtro_uno)
      : (filtro_vincente = filtro_due);
    if (filtro_uno.length === filtro_due.length) {
      return console.log(filtro_uno);
    }
  }
};

const most_uncommon = (filtro_vincente, index) => {
  for (let i of filtro_vincente) {
    index++;

    const filtro_uno = filtro_vincente.filter((e) => e[index] === "1");
    const filtro_due = filtro_vincente.filter((e) => e[index] === "0");

    filtro_uno.length < filtro_due.length
      ? (filtro_vincente = filtro_uno)
      : (filtro_vincente = filtro_due);

    if (filtro_uno.length === filtro_due.length) {
      return console.log(filtro_due);
    }
  }
};

const xygen_generator_rating = (elem_riga, index) => {
  const filtro_uno = elem_riga.filter((e) => e[index] === "1");
  const filtro_due = elem_riga.filter((e) => e[index] === "0");
  filtro_uno.length > filtro_due.length
    ? most_common(filtro_uno, index)
    : most_common(filtro_due, index);
};

const co2_scrubber_rating = (elem_riga, index) => {
  const filtro_uno = elem_riga.filter((e) => e[index] === "1");
  const filtro_due = elem_riga.filter((e) => e[index] === "0");
  filtro_uno.length < filtro_due.length
    ? most_uncommon(filtro_uno, index)
    : most_uncommon(filtro_due, index);
};

const oxgen_gen = xygen_generator_rating(elem_riga, (index = 0));
const co2 = co2_scrubber_rating(elem_riga, (index = 0));
console.log(oxgen_gen, co2);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

most_common() and most_uncommon() shouldn't return the result of console.log(), they should return the variables filtro_uno and filtro_due.

xygen_generator_rating() and co2_scrubber_rating() need to return the results of the ternaries.

const most_common = (filtro_vincente, index) => {
  for (let i of filtro_vincente) {
    index++;
    const filtro_uno = filtro_vincente.filter((e) => e[index] === "1");
    const filtro_due = filtro_vincente.filter((e) => e[index] === "0");
    filtro_uno.length > filtro_due.length
      ? (filtro_vincente = filtro_uno)
      : (filtro_vincente = filtro_due);
    if (filtro_uno.length === filtro_due.length) {
      console.log(filtro_uno);
      return filtro_uno;
    }
  }
};

const most_uncommon = (filtro_vincente, index) => {
  for (let i of filtro_vincente) {
    index++;

    const filtro_uno = filtro_vincente.filter((e) => e[index] === "1");
    const filtro_due = filtro_vincente.filter((e) => e[index] === "0");

    filtro_uno.length < filtro_due.length
      ? (filtro_vincente = filtro_uno)
      : (filtro_vincente = filtro_due);

    if (filtro_uno.length === filtro_due.length) {
      console.log(filtro_due);
      return filtro_due;
    }
  }
};

const xygen_generator_rating = (elem_riga, index) => {
  const filtro_uno = elem_riga.filter((e) => e[index] === "1");
  const filtro_due = elem_riga.filter((e) => e[index] === "0");
  return filtro_uno.length > filtro_due.length
    ? most_common(filtro_uno, index)
    : most_common(filtro_due, index);
};

const co2_scrubber_rating = (elem_riga, index) => {
  const filtro_uno = elem_riga.filter((e) => e[index] === "1");
  const filtro_due = elem_riga.filter((e) => e[index] === "0");
  return filtro_uno.length < filtro_due.length
    ? most_uncommon(filtro_uno, index)
    : most_uncommon(filtro_due, index);
};

const input = `00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010`;
const elem_riga = input.split("\n");

const oxgen_gen = xygen_generator_rating(elem_riga, (index = 0));
const co2 = co2_scrubber_rating(elem_riga, (index = 0));
console.log(oxgen_gen, co2);

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!