File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * 3856. Trim Trailing Vowels
3+ *
4+ * 移除s中後半部的母音
5+ *
6+ * @param {string } s
7+ * @return {string }
8+ */
9+ var trimTrailingVowels = function ( s ) {
10+ /**
11+ * 從後面開始檢查每個字元是否是母音,若是,則移除並繼續往前找直到非母音為止
12+ */
13+
14+ let splitS = s . split ( "" ) . reverse ( ) ;
15+ let i = 0 ;
16+ while ( splitS [ i ] === 'a' || splitS [ i ] === 'e' || splitS [ i ] === 'i' || splitS [ i ] === 'o' || splitS [ i ] === 'u' ) {
17+ splitS . shift ( ) ;
18+ }
19+ return splitS . reverse ( ) . join ( "" ) ;
20+ } ;
21+ // let s = "idea";
22+ //"id"
23+ // let s = "day";
24+ let s = "aeiou" ;
25+ console . log ( trimTrailingVowels ( s ) ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { format } from 'node:path';
33import { ExecutionTimer } from './time.js' ;
44import assert from 'node:assert/strict' ;
55import { count } from 'node:console' ;
6+ import { lchown } from 'node:fs' ;
67
78/*
8922. Generate Parentheses
@@ -1278,34 +1279,3 @@ Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
12781279*/
12791280// console.log(minimumDeletions(s));
12801281
1281- /**
1282- * 3856. Trim Trailing Vowels
1283- *
1284- * 移除s中後半部的母音
1285- *
1286- * @param {string } s
1287- * @return {string }
1288- */
1289- var trimTrailingVowels = function ( s ) {
1290- /**
1291- * 從後面開始檢查每個字元是否是母音,若是,則移除並繼續往前找直到非母音為止
1292- */
1293- // let halfToRemove = Math.round(s.length / 2);
1294- let count = 0 ;
1295- let result = "" ;
1296- let vowels = "aeiou" ;
1297- // console.log(s.slice(0,halfToRemove))
1298- for ( let i = s . length ; i >= 0 ; -- i ) {
1299- if ( s [ i ] != "a" || s [ i ] != "e" || s [ i ] != "i" || s [ i ] != 'o' || s [ i ] != 'u' ) {
1300- result += s ;
1301- } else {
1302- console . log ( "adfdf" )
1303-
1304- }
1305- }
1306- return result ;
1307- } ;
1308- let s = "idea" ;
1309- //"id"
1310- // let s = "day";
1311- console . log ( trimTrailingVowels ( s ) ) ;
You can’t perform that action at this time.
0 commit comments