เรามีอาร์เรย์ที่มีค่าสตริงและค่า false บ้าง
เราต้องเขียนฟังก์ชันที่รับอาร์เรย์นี้และคืนค่าสตริงที่สร้างจากการรวมค่าของอาร์เรย์และละเว้นค่า false
ตัวอย่าง
โค้ดสำหรับนี้:
const arr = ["Here", "is", null, "an", undefined, "example", 0, "", "of", "a", null, "sentence"]; const joinArray = arr => { const sentence = arr.reduce((acc, val) => { return acc + (val || ""); }, ""); return sentence; }; console.log(joinArray(arr));ผลลัพธ์
ผลลัพธ์ในคอนโซล:
Hereisanexampleofasentence