Created
May 12, 2019 12:45
-
-
Save faisalfiraz21/f47f370745308d01434544cdd9cfbdfb to your computer and use it in GitHub Desktop.
Javascript Test For Jabar Digital
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
function createCheckDigit(membershipId) { | |
let sumMembershipId = aggregator(membershipId); | |
while (parseInt(sumMembershipId) > 9) sumMembershipId = aggregator(sumMembershipId); | |
return sumMembershipId; | |
} | |
function aggregator(strMembershipId) { | |
return strMembershipId.toString().split('').reduce((a, b) => parseInt(a) + parseInt(b), 0); | |
} | |
console.log(createCheckDigit("55555")); |
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
function registerHandlers() { | |
var as = document.getElementsByTagName('a'); | |
for (i = as.length; i-- >= 0;) { | |
as[i].onclick = (function(index) { | |
return function() { | |
alert(index); | |
return false; | |
}}(i)); | |
} | |
} | |
/* HTML code for testing purposes (do not submit uncommented): | |
<body> | |
In my life, I used the following web search engines:<br/> | |
<a href="//www.yahoo.com">Yahoo!</a><br/> | |
<a href="//www.altavista.com">AltaVista</a><br/> | |
<a href="//www.google.com">Google</a><br/> | |
</body> | |
*/ |
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
function AddLeadingZero(num) { | |
return (num < 10 ? '0' : '') + num; | |
} | |
function formatDate(userDate) { | |
var [month, day, year] = userDate.split('/'); | |
return year + AddLeadingZero(month) + AddLeadingZero(day); | |
} | |
console.log(formatDate("12/31/2014")); |
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
const ensure = (value) => { | |
if(typeof value === 'undefined' ){ | |
throw new Error(); | |
} | |
else{ | |
return value; | |
} | |
} | |
ensure(); |
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
function setup() { | |
// Write your code here. | |
var els = document.getElementsByClassName('remove'); | |
for (var i = 0; i < els.length; i++) { | |
els[i].addEventListener('click', function () { | |
this.parentNode.remove(); | |
}); | |
} | |
} | |
// Example case. | |
document.body.innerHTML = ` | |
<div class="image"> | |
<img src="https://goo.gl/kjzfbE" alt="First"> | |
<button class="remove">X</button> | |
</div> | |
<div class="image"> | |
<img src="https://goo.gl/d2JncW" alt="Second"> | |
<button class="remove">X</button> | |
</div>`; | |
setup(); | |
document.getElementsByClassName("remove")[0].click(); | |
console.log(document.body.innerHTML); |
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
function appendChildren(decorateDivFunction) { | |
var allDivs = document.getElementsByTagName("div"); | |
allDivs = [].slice.call(allDivs, 0); | |
for (var i = 0; i < allDivs.length; i++) { | |
var newDiv = document.createElement("div"); | |
decorateDivFunction(newDiv); | |
allDivs[i].appendChild(newDiv); | |
} | |
} | |
// Example case. | |
document.body.innerHTML = ` | |
<div id="a"> | |
<div id="b"> | |
</div> | |
</div>`; | |
//appendChildren(function(div) {}); | |
console.log(document.body.innerHTML); |
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
function removeProperty(obj, prop) { | |
if(prop in obj){ | |
delete obj[prop]; | |
return true; | |
}else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment