Hi,
I’m just working my way through some beginner challenges but I’ve hit some stumbling blocks. Please help
- I want to check for 2 to 4 recurrences of a character in a string using regex.
When not a function the code seems to work. How do I make my 2nd argument my regex search term?
I tried it on its own ‘a’ , “a” as a string and as regex /a/.
function check (string, a) {
let regex = /a{2,4}/g
return string.match(regex));
}
console.log(check(“hello”, /l/));
- problem…
function ascending(array){
let ascendingNum = ""
for (let i = 0; i < array.length; i++){
console.log(array[i], array[i-1]);
if (array[i] > array[i-1]){
ascendingNum += array[i];
} else {break;}
}
return ascendingNum;
}
console.log(ascending([1,2,3,4,5]));
when i do this “console.log(array[i], array[i-1])” without the if statement, it gives me the value i’d expect. However, when i put the if statement in console.log doesn’t produce anything anymore and it just produces ‘1 undefined’
I’d ideally like it to produce the array until the numbers are not ascending anymore, in which case, break the loop.
- Also, just another question. If my argument is an array, do I have to write my parameter as an array in [array] like this, or can it not be in the brackets?
Thanks for your help!