P
P
pandaa2019-05-31 12:44:47
Algorithms
pandaa, 2019-05-31 12:44:47

There is a set of numbers, how to determine that they end with a certain number?

for example there are some numbers: 54, 3, 25, 47 find out which one ends with 4

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-05-31
@pandaa

arr.filter(n => n % 10 === 4)
or or or
arr.filter(n => /4$/.test(n))
arr.filter(n => ''.endsWith.call(n, 4))
(`${arr}`.match(/\d*4(?=\D)/g) || []).map(Number)

E
Evgeny Samsonov, 2019-05-31
@bitniks

int n = 4;
int numbers[n] = {54, 3, 25, 47};
for (int i = 0; i < n; i++) {
    if (numbers[i] % 10 == 4) {
        cout << numbers[i] << endl; 
    }
}

https://onlinegdb.com/SJAXWKCTE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question