Albatta bu masalani har xil yechimlari bor. Men ham ulashmoqchi edim let m = [1, 4, 5, 3]; const k = (param) => { if (!param.length) { return console.log("massiv ichida malumot yo'q"); } else { let strM = param.join(""); let firstM = strM.slice(0, param.length - 1); let lastM = strM.slice(param.length - 1); return (firstM + ((parseInt(lastM) + 1) % 10)) .toString() .split("") .map(Number); } }; console.log(k(m));
let arr = [1,2,3]; function calc(array){ if (array.length == 0) { return "no element"; } else { let number = (arr.join("")) * 1 + 1 + "" let result = number.split("") return result.map(Number) } } console.log(calc(arr))
let arr = [1, 3, 1];
let i = arr.length;
arr = arr.join('');
if (arr % 10 == 9) arr -= 9;
else arr++;
let newAr = [];
while (arr) {
newAr[--i] = arr % 10;
arr = parseInt(arr / 10);
}
console.log(newAr);
Albatta bu masalani har xil yechimlari bor. Men ham ulashmoqchi edim
let m = [1, 4, 5, 3];
const k = (param) => {
if (!param.length) {
return console.log("massiv ichida malumot yo'q");
} else {
let strM = param.join("");
let firstM = strM.slice(0, param.length - 1);
let lastM = strM.slice(param.length - 1);
return (firstM + ((parseInt(lastM) + 1) % 10))
.toString()
.split("")
.map(Number);
}
};
console.log(k(m));
Aka ishiyiz ajoyib. Qoyilmaqom!
Hamma ishga har xil yondoshadi. Ishiyizga omad😀😃😄😇
aka oma maldes svoldiyam jinnisi tushakanakan o'ziyam
let arr = [1,2,3];
function calc(array){
if (array.length == 0) {
return "no element";
} else {
let number = (arr.join("")) * 1 + 1 + ""
let result = number.split("")
return result.map(Number)
}
}
console.log(calc(arr))
oka toppa tori bu dalbayob rosa aylantirdi
function oshirish_va_aylantirish(massiv) {
massiv[massiv.length - 1] += 1; // Oxirgi elementni 1 ga oshiramiz
return massiv;
}
let massiv = [1, 2, 9];
let yangiMassiv = oshirish_va_aylantirish(massiv);
console.log(yangiMassiv);
Assalomalekum siz bn qanday boglansam boladi aka
va alaykum assalom. t.me/smd_94
Vidioga kim gap qo'shgan
Darsdan video record qilib olingan. Darsdagi bollani ovozi
juda yomon usulda yondashilgan masalaga, js bu c++ emas
man ham shunday fikrdaman, qiyinroq usulda yondashilgan
juda eski sintaksisda iwlanibdi va juda qiyin yol bilan ketib qolgan
Ha bu 1 yil oldingi edi. Buni str holatida birni qoshib split qilsa ham chiqadi. Eng sodda yoli
@@WebbrainAcademy men ham shuni aytmoqchi edim
shunda optimalroq yechim boʻlar edi
@@WebbrainAcademy ++
const arr = [1, 2, 3];
const arrString = arr.join("");
let s = arrString.charAt(arrString.length - 1);
s++;
const newString = arrString.replace(
arrString.charAt(arrString.length - 1),
s.toString()
);
const newArr = newString.split("");
console.log(newArr);
masalani eshitib videoni tohtatib keyin yozdim, lekin ishonaman bundan yaxshi algoritmlar tiqilib yotibti😄
sizlarni kodlariz uzun ekan lekin
const arr = ["1", "2", "3"];
function increaseEl(arr) {
if (!arr.length) {
return "Array is empty";
} else {
const numberStr = arr.join("");
const numberInt = parseInt(numberStr);
const result = numberInt + 1;
const stringResult = result.toString();
return stringResult.split("");
}
}
console.log(increaseEl(arr));