describe("handlingString", () => { it("should return false if the length of the string is not 4 or 6", () => { expect(handlingString("Jane")).toBe(false); expect(handlingString("JaneKim")).toBe(false); });
it("should return false if the string contains non-numeric characters", () => { expect(handlingString("Jan123")).toBe(false); expect(handlingString("J123")).toBe(false); });
it("should return true if the string is composed of numeric characters", () => { expect(handlingString("1234")).toBe(true); expect(handlingString("123456")).toBe(true); }); });
문제출처
프로그래머스
다른 풀이
1 2 3 4
functionalpha_string46(s){ var regex = /^\d{6}$|^\d{4}$/; return regex.test(s); }