Please help me how to change the letter in the array without creating a new array ?
Can you show us what code you have tried so far?
array[0].charAt(0) = “9”;
let array = [‘109’, ‘102’, ‘100’, ‘030’, ‘020’, ‘006’, ‘001’];
You have to fully replace array[0]
since it is a string. You can’t just change part of it.
Side note - the more code you show, the easier it is for us to understand what’s going on.
For example, I need 101 to get 901.
Let’s just say that such a function should be replaced by 9 so that there is a maximum difference in the sum
let array = ['109', '102', '100', '030', '020', '006', '001'];
let k = 5;
let swith = 0;
function replacement(k, array) {
for (let i = 0; i < k; i++) {
for (let j = 0; j < array.length; j++) {
let firstLetter = array[j].charAt(swith);
if (firstLetter != "0" && firstLetter != "9") {
let currentValue = array[j];
if (minValue == null || currentValue < minValue) {
minValue = currentValue;
};
} else {
break;
};
};
};
};
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.