JavaScriptでタイポグリセミア
何
最初と最後の文字さえ合っていればその間の文字が並び替えられていても読めちゃうやつ
dic.nicovideo.jp
もっとよい実装方法はあるはず
const word = "つらくてもいきてゆく"; const first = word.charAt(0); //先頭の文字は不動 let otherArr = word.substr(1, word.length - 2).split(""); //残りの文字列を1文字ずつ配列に格納 const last = word.charAt(word.length - 1); //最後の文字は不動 //配列の中身をランダムに入れ替える for (let i = otherArr.length - 1; i > 0; i--) { let r = Math.floor(Math.random() * (i + 1)); let tmp = otherArr[i]; otherArr[i] = otherArr[r]; otherArr[r] = tmp; } //配列を文字列に変換し、カンマを取り除く const otherStr = otherArr.toString().replace(/,/g, ""); //文字列を先頭から順に合体 const ans = first.concat(otherStr, last); console.log(ans); // つくゆきもてらいてく
もっと簡単に書けるしスマートにできるだろ
優しく教えてください
あと変数の命名についても教えてくださいこの場合最初と最後はfirst と lastにしたんですけどその間全部のことは何て言うのかがわかりません、otherでいいんですか?つらいです