Skip to content

Instantly share code, notes, and snippets.

@afrieirham
Created May 21, 2019 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afrieirham/2a090d219654e7c6c83c3287329cc126 to your computer and use it in GitHub Desktop.
Save afrieirham/2a090d219654e7c6c83c3287329cc126 to your computer and use it in GitHub Desktop.
Digi-X Section 2
// 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