1
You are going to be given a word. Your job is to return the middle character of the word. If the word’s length is odd, return the middle character. If the word’s length is even, return the middle 2 characters.
function getMiddle(s) { if (s.length == 1) { return s } else { return (s.length % 2 === 0) ? s[s.length / 2 - 1] + s[s.length / 2] : s[(s.length - 1) / 2] } }
2
Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters,
each taken only once - coming from s1 or s2. #Examples: a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq" longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmnopqrstuvwxyz" longest(a, a) -> "abcdefghijklmnopqrstuvwxyz"
这里写代码片
function descendingOrder(n) { return Number(String(n).split("").sort(function(a,b){return b-a}).join("")) }
function digital_root(n) { var str=String(n); if(str.length===1){ return n } else{ for(var i= 0,l=str.length,r=0;i<l;i++){ r+=Number(str[i]); } return digital_root(r) } }
不考虑太多东西了,直接写个简单的
function isTriangle(a,b,c) { if(a+b>c&&a+c>b&&c+b>a){ return true }else{ return false } }