Computer >> Máy Tính >  >> Lập trình >> Javascript

Xóa nguyên âm cuối - JavaScript

Chúng tôi bắt buộc phải viết một hàm JavaScript nhận vào một chuỗi và trả về một chuỗi mới với nguyên âm cuối cùng của mỗi từ bị xóa.

Ví dụ - Nếu chuỗi là -

 const str ='Đây là một chuỗi mẫu'; 

Sau đó, đầu ra phải là -

 const output ='Ths s n exampl strng'; 

Ví dụ

Sau đây là mã -

 const str ='Đây là một chuỗi mẫu'; const removeLast =word => {const lastIndex =el => word.lastIndexOf (el); const ind =Math.max (lastIndex ('a'), lastIndex ('e'), lastIndex ('i'), lastIndex ('o'), lastIndex ('u')); return word.substr (0, ind) + word.substr (ind + 1, word.length);} const removeLastVowel =str => {const strArr =str.split (''); return strArr.reduce ((acc, val) => {return acc.concat (removeLast (val));}, []). join ('');}; console.log (removeLastVowel (str));  

Đầu ra

Sau đây là đầu ra trong bảng điều khiển -

 Ths s n exampl strng