Last active
November 17, 2020 10:08
-
-
Save vishu3278/1b08d6cb84ac96277eb6652149dcdea7 to your computer and use it in GitHub Desktop.
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
/* Part 1 */ | |
/* Q1 */ | |
var array = []; | |
var i = 0; | |
while (i < 101) { | |
array.push(i); | |
i++; | |
} | |
console.log(array); | |
/* Q2 */ | |
function checkEven(number) { | |
return number % 2 == 0; | |
} | |
var even = array.filter(checkEven); | |
console.log(even); | |
/*Q3*/ | |
function square(number) { | |
if (number%2 == 0) { | |
return number*number | |
} else { | |
return "Odd number passed" | |
} | |
}var square = even.map(squareOut); | |
console.log(square); | |
/*Q4*/ | |
function sumArray(arr){ | |
return arr.reduce(function(a,b){ | |
return a + b | |
}, 0); | |
} | |
console.log(sumArray(square)); | |
/* Part 2 */ | |
/* Q1 (answered in vue.js)*/ | |
export default { | |
data: function() { | |
return { | |
btnTitle: 'Button title' | |
} | |
} | |
} | |
</script> | |
<template> | |
<button v-bind:title="btnTitle"></button> | |
</template> | |
/* Q2 (answered in vue.js) */ | |
<template> | |
<ol> | |
<li v-for="n of 30" v-bind:key="n">{{n}}</li> | |
</ol> | |
</template> | |
/* Q3 */ | |
<template> | |
<ol> | |
<li v-for="n of 30" v-bind:key="n"><span v-if="n % 2 == 0">{{n}}</span></li> | |
</ol> | |
</template> | |
/* Q4 (not complete ) */ | |
let randomDelay = new Promise(function(resolveCallback,rejectCallback) { | |
let randomdelay = Math.floor((Math.random() * 3)+1); | |
resolveCallback(randomdelay); | |
}); | |
randomDelay.then((value)=>{ | |
document.getElementById("demo").innerHTML = value; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment