Codewars

[Solved] Codewars | Perl - Code Explorer | yomemimo.com
Question : codewars

Answered by : mohammad-alshraideh

// codewars:Regex validate PIN code
function validatePIN (pin) { //return true or false return /^(\d{4}|\d{6})$/.test(pin)
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

//codewars :Replace With Alphabet Position
function alphabetPosition(text) { var result = ""; for (var i = 0; i < text.length; i++) { var code = text.toUpperCase().charCodeAt(i) if (code > 64 && code < 91) result += (code - 64) + " "; } return result.slice(0, result.length - 1);
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

// codewars:Sum of Digits / Digital Root
function digitalRoot(n) { let result = 0; String(n).split('').map(num => { result += Number(num); }); return result >= 10 ? digitalRoot(result) : result;
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

//codewars:Credit Card Mask
function maskify(str) {
if(str ==='' || str ==="") return "" let length =str.split(" ").join("").split("").length let x = str.split(" ").join("").split("").map((m, i)=>{ if(i<length-4){ m="#" }else{m=m} return m; })
return x.join("")
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

// codewars : Bouncing Balls
function bouncingBall(h, bounce, window) { // your code here if (h > 0 && bounce > 0 && bounce < 1 && window < h) { let count = 1; let n =25 for (let i = 1; i < n; i++) { h= h * bounce
if(h > window){ count = count+2;
}else {
break}; } return count; } else return -1;
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

//codewars:Jaden Casing Strings
String.prototype.toJadenCase = function () { //... var str = "How can mirrors be real if our eyes aren't real"; if(this ==='' || this ==="") return "" let x = this.split(" ").map((m)=>{ return m.charAt(0).toUpperCase() + m.slice(1).toLowerCase() }).join(" ")
return x
};

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

//codewars:Shortest Word
function findShort(str){ let length = Infinity ; let y = ""; let x = str.split(" ").map((m)=>{ if(m.length < length ){ length = m.length; y=m } else if(m.length == length ){ length = m.length; y= y +' '+m } })
return y.split(" ")[0].length
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

///codewars : Moving Zeros To The End
function moveZeros(num) { let length = num.length; let x= num.filter((m)=>
m != 0 || !typeof m === "number" || typeof m === "boolean" || typeof m ==='object'|| typeof m ==='string' ) let n=length-x.length; for(let i=0; i<n; i++){ x.push(0) } return x ;
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

//codewars :Friend or Foe?
function friend(friends){ return friends.filter((m)=> m.length == 4 && m.match(/^[a-zA-Z]/g)
)
}

Source : | Last Update : Wed, 16 Nov 22

Question : codewars

Answered by : mohammad-alshraideh

//codewars:Convert string to camel case
function toCamelCase(str){ //console.log(str, 'testing') if(str === ''){ return '' } else { let containmentArea = [] let splitString = str.replace(/[^A-Z0-9]/ig, "_").split("_") //[ 'the', 'stealth', 'warrior' ] let firstElement = containmentArea.push( splitString.splice(0,1) ) for(let word in splitString){ let splitWords = splitString[word].split('') let capitalLetter = splitWords[0].toUpperCase() splitWords.splice(0,1, capitalLetter) let joinedWord = splitWords.join('') containmentArea.push(joinedWord) let newSentence = containmentArea.join('') } return containmentArea.join('') }
}

Source : | Last Update : Wed, 16 Nov 22

Answers related to codewars

Code Explorer Popular Question For Perl