Categories
Medium Problems

โจทย์ข้อที่ MX0006

จงเขียนฟังก์ชั่นที่รับค่า string ที่เป็นชื่อและนามสกุลเข้าไป แล้วส่ง string ที่สลับตำแหน่งชื่อ และสกุลนั้นออกมา

Examples

nameShuffle(“donald trump”) ➞”trump donald”

nameshuffle(“rosie o’donnell”) ➞ “o’donnell rosie”

nameshuffle(“seymour butts”) ➞ “butts seymour”

Categories
Medium Problems

โจทย์ข้อที่ MX0005

จงเขียนฟังก์ชั่นที่ส่งค่า true ออกมา หาก array ที่ใส่เข้าไปมีสมาชิกที่มีค่าเท่ากับหรือมากกว่าตัวเลขที่ใส่เป็นตัวที่สอง นอกนั้นให้ส่ง false ออกมา

Examples

existsHigher([5, 3, 15, 22, 4], 10) ➞ true

existsHigher([1, 2, 3, 4, 5], 8) ➞ false

existsHigher([4, 3, 3, 3, 2, 2, 2], 4) ➞ true

existsHigher([], 5) ➞ false

Categories
Medium Problems

โจทย์ข้อที่ MX0004

จงเขียนฟังก์ชั่นที่รับค่าตัวเลขจำนวนเต็มเข้าไป 2 ตัว และตัวดำเนินทางคณิตศาสตร์ (+, – , * , /) และให้คำนวณตามตัวดำเนินการนั้นแล้วส่งค่าผลลัพธ์ออกมา

Examples

calculator(2, ‘+’, 2) ➞ 4

calculator(2, ‘*’, 2) ➞ 4

calculator(4, ‘/’, 2) ➞ 2

Categories
Medium Problems

โจทย์ข้อที่ MX0002

จงเขียนฟังก์ชั่นที่รับข้อมูล string ของไป 2 ตัว แล้วให้ส่งค่า true ออกมา หาก string ตัวแรกลงท้ายด้วย string ตัวที่ 2 นอกเหนือจากนั้นให้ส่ง false ออกมา

Examples

checkEnding(“abc”,”bc”) ➞ true

checkEnding (“abc”,”d”) ➞ false

Categories
Medium Problems

โจทย์ข้อที่ mx0001

จงเขียนฟังก์ชั่นที่รับ string ที่เป็นประโยคเข้าไป แล้วส่งค่าจำนวนคำที่นับได้ออกมา


Examples

countWords(” just an example here move along”) ➞ 6

countwords(“this is a test”) ➞ 4