+ 1

Help please! How console this??

The program has a partNumbers variable that stores an array. Each array element is a product SKU. Write a program that will create a new array based on partNumbers . The new array must contain all elements from partNumber that end in two digits and two alphabetic characters. All other elements must be discarded. Print the value of the new array to the console . Variable value example : partNumbers = [ " ER1234COM " , " FIV987451RU " , " GE123JO " , " P4321NO " ] Result example : [ " FIV987451RU " , " GE123J0 " , " P4321N0 " ]

13th Jul 2022, 8:57 PM
Yasha Mayorov
Yasha Mayorov - avatar
4 Réponses
+ 1
Abhay sorry, its my mistake) Thank so much!)
16th Jul 2022, 2:50 PM
Yasha Mayorov
Yasha Mayorov - avatar
0
you can loop over array. Then check each item the following way, a="abc45de" // example string. len=a.length chr=/[a-zA-Z]/ alpha=/[0-9]/ console.log(chr.test(a[len-1]) && chr.test(a[len-2])&& alpha.test(a[len-3]) && alpha.test(a[len-4])) ;use above condition in if statement . If it is true add item to new array .
13th Jul 2022, 11:24 PM
Abhay
Abhay - avatar
0
This example gives false when it should be true
14th Jul 2022, 6:25 AM
Yasha Mayorov
Yasha Mayorov - avatar
0
Yasha Mayorov gives true to me
14th Jul 2022, 7:45 AM
Abhay
Abhay - avatar