I want a string to return a length of multiple of 8 for example if I’ve 123456789
so here I need to return a string 12345678 removing the last digit
Example 2:
for instance string length is 123456789123=>here it should remove 9123 and return me 1234
5678
I’m returning a string length when I pass the length of string to be 8 the length that are not multiple of 8 I should make them multiple of 8 by removing the exessive characters
>Solution :
You can start with this example:
function getStringMultipleOfEight(str) {
const remainder = str.length % 8;
const newLength = str.length - remainder;
return str.substring(0, newLength);
}
console.log(getStringMultipleOfEight('123456789')); // Output: '12345678'
console.log(getStringMultipleOfEight('123456789123')); // Output: '12345678'