0

Below is the code I unsuccessfully try to run in the console of chrome. Now the code of which looks like this and does not actually work.

Test.provide = Test.data = function arraaays() {
const c = [];

for (let i = 0; i < Math.max(a.length, b.length); i++) {
    if (a[i] !== undefined) {
        c.push(a[i]);
    }

    if (b[i] !== undefined) {
        c.push(b[i]);
    }
}

console.log(c);
}

The code itself should interact with two arrays that are in Test.data and create a new one of this type on their basis

a: ['a', 'b', 'c'] //first array
b: ['d', 'e'] //second array
c: ['a', 'd', 'b', 'e', 'c'] // new array
trigun117
  • 639
  • 7
  • 21
  • how are you running that function? and what is `Test` anyway? – Jaromanda X Sep 15 '17 at 03:35
  • `The code itself should interact with two arrays that are in Test.data` - you've clobbered `Test.data` with the function – Jaromanda X Sep 15 '17 at 03:36
  • [Possible related question](https://stackoverflow.com/questions/3975170/javascript-how-to-join-combine-two-arrays-to-concatenate-into-one-array) – Ram Sep 15 '17 at 03:37
  • and, also, the result will actually be `[ "a", "d", "b", "e", "c", undefined ]` - because `undefined !== null` – Jaromanda X Sep 15 '17 at 03:38
  • @JaromandaX Data in Test.data `>Test.data <{a: Array(10), b: Array(10)} a: Array(10) 0 :"LfXbYpHqGr" 1:"qCxXsQdYu" 2:"xXlLnIl" 3:"UhHaOa" 4:"Zg" 5:"hIt" 6:"mAkXh" 7:"kDwOqOz" 8:"LlInXvWsVv" 9:"EyIbEzGpSk" b: Array(10) 0:"mKjRvTf" 1:"Hs" 2:"RmNxQw" 3:"yIxZn" 4:"d" 5:"c" 6:"aAe" 7:"SkIuCbZuZq" 8:"h" 9:"KiTc"` I do not create objects, I'm working with ready objects. I just need to force the code to interact with the data in the object. – trigun117 Sep 15 '17 at 10:38

1 Answers1

0
function arry(a, b) {
var c = [];

for (let i = 0; i < Math.max(a.length, b.length); i++) {
    if (a[i] != undefined) {
        c.push(a[i]);
    }

    if (b[i] != undefined) {
        c.push(b[i]);
    }
}
return c;
}
Test.provide = arry(Test.data.a, Test.data.b);
trigun117
  • 639
  • 7
  • 21