refactor the code by using the method filter and getting the length from the array