Help

Re: When updating my array, something strange happens

1204 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi there -

When I run this code, I am getting extra commas and the values are not lining up. What am I doing wrong?

let vowels = “aeiou”
let sentence = “Your ass is so beautiful”

let mda=
let fullsetofzeros =
var i
var j

for (i = 0; i < vowel.length; i++) { // p1
mda[i] = 0
}

for (i= 0; i < sentence.length; i++) { // p1
fullsetofzeros.push(mda)
}

output.text(Matrix of zeroes ${fullsetofzeros})

for (i= 0; i < vowel.length; i++) { // p1
for (j= 0; j < sentence.length; j++) { // p1
if (vowel.includes(sentence[j])) {
fullsetofzeros[i][j]= 1
}
}
}

output.text(Matrix after test ${fullsetofzeros}) When updating my array, something strange happens

2 Replies 2

Hmmm…discourse doesn’t like the a-word.

Anyway, here’s some amended code:

let vowels = 'aeiou';
let sentence = 'Your *** is so beautiful';

let mda = []; 
let fullsetofzeros = [];
var i;
var j;

for (i = 0; i < vowels.length; i++) {
    mda[i] = 0
}

console.log('mda', mda);

for (i = 0; i < sentence.length; i++) {
    fullsetofzeros.push(mda)
}

console.log('fullsetofzeros', fullsetofzeros);

for (j= 0; j < sentence.length; j++) {
    for (i= 0; i < vowels.length; i++) {
        if (vowels.includes(sentence[j])) {
            fullsetofzeros[j][i]= 1
        }
    }   
}
console.log('fullsetofzeros', fullsetofzeros);

Can you give some more context on what you are trying to achieve here? Console.log shows the array structure better, so good to use this, but other than that don’t know what to advise.

Hi Jonathan - What I am trying to achieve is to build a matrix that indexes a binary true or not true for multiple sets of items.

For some reason when I run my code, it is either updating to undefined or updating even when not indexed to update.

Any help would be appreciated.