猿问

一个函数,如果数组第一个字符串元素包含了第二个字符串元素的所有字符,函数返回true

忽略大小写。
举例
fun(["hello", "hey"]) 返回 false.
fun(["hello", "Hello"]) 返回 true.
fun(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) 返回 true.
fun(["Mary", "Army"]) 返回 true.
fun(["Mary", "Aarmy"]) 返回 true

慕运维8079593
浏览 108回答 2
2回答

米琪卡哇伊

<script type="text/javascript">document.write("hello:hey -----"+fun(["hello", "hey"])+"</br>");document.write("zyxwvutsrqponmlkjihgfedcba:qrstu -----"+fun(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])+"</br>" );document.write("Mary:Army -----"+fun(["Mary", "Army"])+"</br>");document.write("Mary:Aarmy -----"+fun(["Mary", "Aarmy"])+"</br>");function fun(arrs){var temp1 = arrs[0].toUpperCase();var temp2=arrs[1].toUpperCase();var flag =true;for(var i=0;i<temp2.length;i++){if(temp1.indexOf(temp2.charAt(i))==-1){flag = false;}}return flag;}</script>

大话西游666

function&nbsp;test(arr){&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;i&nbsp;=&nbsp;0&nbsp;;&nbsp;i&nbsp;<&nbsp;arr[1].length&nbsp;;&nbsp;i++){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(arr[0].toUpperCase().indexOf(arr[1].charAt(i).toUpperCase())&nbsp;==&nbsp;-1){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;}如果需要匹配大小写就把.toUpperCase()去掉
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答