Created
May 21, 2019 16:09
-
-
Save afrieirham/2a090d219654e7c6c83c3287329cc126 to your computer and use it in GitHub Desktop.
Digi-X Section 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question 1 | |
var i=0; | |
var mulArr = []; | |
while(i<=100){ | |
if(i%3 == 0 || i%5 == 0){ | |
mulArr.push(i) | |
} | |
i++; | |
} | |
console.log('Question 1'); | |
console.log(mulArr) | |
// Question 2 | |
var arr = [100, 2, 5, 13, 29, 68, 87, 4, 17, 45, 54]; | |
for(var i=0; i<arr.length; i++){ | |
for(var j=0; j<i; j++){ | |
arr[i]<arr[j]? arr[j] = [arr[i], arr[i] = arr[j]][0] : null; | |
} | |
} | |
console.log('Question 2'); | |
console.log(arr); | |
// Question 3 | |
var testStr = ['tacocat', 'racecar', 'beanbag', 'Hannah']; | |
console.log('Question 3'); | |
console.log(testStr.map(str => isPalindrome(str))) | |
function isPalindrome(str){ | |
return str.toLowerCase() == str.toLowerCase().split('').reverse().join('')? true : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment