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

144
Views
obtain from a matrix where the 0 will be space and if X is repeated

I need to understand how with an array of numbers, divide it into blocks when the number zero appears, this marks the beginning and end of this and another block.

Which I must sort in ascending order and that when printing the sequences must be separated by a space where the zero was and if there is a sequence of zeros, X would be printed.

Example 1: [1,3,2,0,7,8,1,3,0,6,7,1]. The result: 123 1,378 167 Example 2: [2,1,0,0,3,4]. The result: 12X34.

var myArray = [1,3,2,0,7,8,1,3,0,6,7,1] 
    
let salida ='';
let salida_temp = []

for(let i = 0; i < array.length; i++){
    if(array[i] !== 0 && i+1 < array.length)
       salida_temp.push(array[i])
    else{ 
       if(i+1 == myArray.length){
         salida_temp.push(myArray[i])
   }

Tank's

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

0

You have to go through series of consecutive steps to achieve the desired result.

function separateNumber(arr) {
  return arr
    .join("")
    .replace(/(0)\1+/g, "0X0")
    .split("0")
    .map((s) => s.split("").sort().join(""))
    .join(" ")
    .replace(/ X /g, "X");
}

console.log(separateNumber([1, 3, 2, 0, 7, 8, 1, 3, 0, 6, 7, 1]));
console.log(separateNumber([2, 1, 0, 0, 3, 4]));
console.log(separateNumber([2, 0, 1, 0, 0, 3, 4]));
console.log(separateNumber([2, 1, 0, 0, 3, 4, 0, 0, 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!