Ad
Algorithms
Logic
Arrays
Data Types

Join two arrays of the same length by placing one value from the first array, then one from the second, and so on.

const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];

zip(arr1, arr2); // returns => [1, 'a', 2, 'b', 3, 'c']
function zip(arr1, arr2) {
  const result = [];

  for (let i = 0; i < arr1.length; i++) {
    result.push(arr1[i], arr2[i]);
  }

  return result;
}

Idea for Kata
You are given an endpoint server and an array of objects {server-sender, server-receiver}. The task is to find the initial server from which the request was submitted.

Example:
proxyDecoder('Vanuatu174', [{from: 'Tonga6120', to: 'SouthAfrica1124' }, { from: 'SouthAfrica1124', to: 'Paraguay8257' }, { from: 'Paraguay8257', to: 'Vanuatu174' }] -> 'Tonga6120'

I have already written several functions for creating a random array to test. It is necessary to create a function that combines endpoint and array, to randomize the sorting and to add extra queries that are not related to the task. And find bugs, of course

function getRandomServer () {
let countries = ["Afghanistan","Albania","Algeria","Andorra","Angola","AntiguaBarbuda","Argentina","Armenia","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bhutan","Bolivia","BosniaHerzegovina","Botswana","Brazil","Brunei","Bulgaria","BurkinaFaso","Burundi","CaboVerde","Cambodia","Cameroon","Canada","Chad","Chile","China","Colombia","Comoros","Congo","CostaRica","CoteD’Ivoire","Croatia","Cuba","Cyprus","Czech","Denmark","Djibouti","Dominica","Ecuador","Egypt","ElSalvador","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","KoreaNorth","KoreaSouth","Kosovo","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Micronesia","Monaco","Mongolia","Montenegro","Morocco","Mozambique","Namibia","Nauru","Nepal","Netherlands","NewZealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palau","Panama","PapuaNewGuinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Samoa","SaudiArabia","Senegal","Serbia","Seychelles","SierraLeone","Singapore","Slovakia","Slovenia","Somalia","SouthAfrica","Spain","SriLanka","Sudan","Sudan","South","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Togo","Tonga","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","Emirates","UK","USA","Uruguay","Uzbekistan","Vanuatu","Vatican","Venezuela","Vietnam","Yemen","Zimbabwe"];
let count = Math.floor(Math.random()*countries.length-1);
let random2 = Math.floor(Math.random()*10000);
return `${countries[count]}${random2}`;
}

function getServersArray (num) {
  let array = [];
  for (let i=0; i<num; i++){
    array.push(getRandomServer());
  }
  return array;
}

function getProxyArray () {
  let random = Math.floor(Math.random()*20);
  if (random<2) getProxyArray ();
  let serversArray = getServersArray(random);
  let array = [];
  for (let i=0; i<random-1; i++){
    array.push({from: serversArray[i], to: serversArray[i+1]});
  }
  let endpoint = serversArray[serversArray.length-1];
  let finalArray = array.sort(()=>Math.random()*100); //need to change this sorting, it's bad
  console.log(endpoint, finalArray) //instead this function should return the example
  return finalArray;
}

getProxyArray ()