diff --git a/src/carbon-dating.js b/src/carbon-dating.js index 8b53e0136e..6c3f2d8906 100644 --- a/src/carbon-dating.js +++ b/src/carbon-dating.js @@ -17,9 +17,13 @@ const HALF_LIFE_PERIOD = 5730; * dateSample('WOOT!') => false * */ -function dateSample(/* sampleActivity */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function dateSample( sampleActivity ) { + if (typeof sampleActivity !== 'string' || sampleActivity === '' || !Number(sampleActivity) || Number(sampleActivity) <= 0 || Number(sampleActivity) > 15){ + return false; + } + const k = Math.LN2 / HALF_LIFE_PERIOD; + const age = Math.log(MODERN_ACTIVITY / Number(sampleActivity)) / k; + return Math.ceil(age); } module.exports = { diff --git a/src/common-character-count.js b/src/common-character-count.js index 681b1f6656..1df36013d8 100644 --- a/src/common-character-count.js +++ b/src/common-character-count.js @@ -11,10 +11,16 @@ const { NotImplementedError } = require('../lib'); * For s1 = "aabcc" and s2 = "adcaa", the output should be 3 * Strings have 3 common characters - 2 "a"s and 1 "c". */ - -function getCommonCharacterCount(/* s1, s2 */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function getCommonCharacterCount( s1, s2 ) { + return s1.split('').reduce((prev, value, i) => { + let index = s2.indexOf(value); + if ( index !== -1 ){ + prev += 1; + s2 = s2.replace(s2[index], ''); + return prev; + } + return prev; + },0) } module.exports = { diff --git a/src/count-cats.js b/src/count-cats.js index e178c79f6c..e208199813 100644 --- a/src/count-cats.js +++ b/src/count-cats.js @@ -14,9 +14,16 @@ const { NotImplementedError } = require('../lib'); * ]) => 3` * */ -function countCats(/* matrix */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function countCats( matrix ) { + let count = 0; + for (let i = 0; i < matrix.length; i++) { + for (let j = 0; j < matrix[i].length; j++) { + if (matrix[i][j] === "^^"){ + count += 1; + } + } + } + return count; } module.exports = { diff --git a/src/delete-digit.js b/src/delete-digit.js index c4f3a2d212..b685ea7007 100644 --- a/src/delete-digit.js +++ b/src/delete-digit.js @@ -11,9 +11,14 @@ const { NotImplementedError } = require('../lib'); * For n = 152, the output should be 52 * */ -function deleteDigit(/* n */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function deleteDigit( n ) { + let str = n.toString(); + let arrSumm = []; + for (let i = 0; i < str.length; i++) { + let newSumm = Number(str.replace(str[i], '')); + arrSumm.push(newSumm); + } + return Math.max(...arrSumm) } module.exports = { diff --git a/src/dns-stats.js b/src/dns-stats.js index 4c1d845c43..37eb491dbd 100644 --- a/src/dns-stats.js +++ b/src/dns-stats.js @@ -22,9 +22,23 @@ const { NotImplementedError } = require('../lib'); * } * */ -function getDNSStats(/* domains */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function getDNSStats( domains ) { + const objDNS = {}; + for (let i = 0; i < domains.length; i++) { + let reverseArr = domains[i].split('.').reverse(); + let dns = ''; + for (let j = 0; j < reverseArr.length; j++) { + dns += `.${reverseArr[j]}`; + if(objDNS[dns]){ + objDNS[dns]++; + } + else{ + objDNS[dns] = 1; + } + } + + } + return objDNS; } module.exports = { diff --git a/src/dream-team.js b/src/dream-team.js index ca4b688b5d..edfd14e560 100644 --- a/src/dream-team.js +++ b/src/dream-team.js @@ -13,9 +13,18 @@ const { NotImplementedError } = require('../lib'); * createDreamTeam(['Olivia', 1111, 'Lily', 'Oscar', true, null]) => 'LOO' * */ -function createDreamTeam(/* members */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function createDreamTeam( members ) { + if(!Array.isArray(members)){ + return false; + } + + return members.reduce((prev, value) => { + if(typeof value === 'string'){ + prev.push(value.trim().at(0).toUpperCase()); + return prev; + } + return prev; + }, []).sort().join(''); } module.exports = { diff --git a/src/encode-line.js b/src/encode-line.js index c77a2954dc..00f2be2a03 100644 --- a/src/encode-line.js +++ b/src/encode-line.js @@ -1,3 +1,4 @@ +// const { NotImplementedError } = require("../extensions/index.js"); const { NotImplementedError } = require('../lib'); /** @@ -10,12 +11,25 @@ const { NotImplementedError } = require('../lib'); * For aabbbc should return 2a3bc * */ +function encodeLine(str) { + if(str.length === 0) return ''; + let result = ""; + let currentChar = str[0]; + let count = 1; -function encodeLine(/* str */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); + for (let index = 1; index < str.length; index++) { + if (currentChar === str[index]) { + count++; + } else { + result += (count > 1 ? count : "") + currentChar; + currentChar = str[index]; + count = 1; + } + } + result += (count > 1 ? count : "") + currentChar; + return String(result); } module.exports = { - encodeLine + encodeLine, }; diff --git a/src/get-email-domain.js b/src/get-email-domain.js index 0fb58b1273..f2031a71bb 100644 --- a/src/get-email-domain.js +++ b/src/get-email-domain.js @@ -10,8 +10,9 @@ const { NotImplementedError } = require('../lib'); * For the input 'prettyandsimple@example.com', the output should be 'example.com' * */ -function getEmailDomain(/* email */) { - throw new NotImplementedError('Not implemented'); +function getEmailDomain( email ) { + const index = email.lastIndexOf('@'); + return email.slice(index +1 ); } module.exports = { diff --git a/src/hanoi-tower.js b/src/hanoi-tower.js index 9df72f988e..49b7db9a74 100644 --- a/src/hanoi-tower.js +++ b/src/hanoi-tower.js @@ -14,9 +14,10 @@ const { NotImplementedError } = require('../lib'); * calculateHanoi(9, 4308) => { turns: 511, seconds: 427 } * */ -function calculateHanoi(/* disksNumber, turnsSpeed */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function calculateHanoi( disksNumber, turnsSpeed ) { + const turns = Math.pow(2, disksNumber) - 1; + const seconds = Math.floor(turns / turnsSpeed * 3600); + return { turns, seconds }; } module.exports = { diff --git a/src/matrix-elements-sum.js b/src/matrix-elements-sum.js index 813b771fa8..690b5a9244 100644 --- a/src/matrix-elements-sum.js +++ b/src/matrix-elements-sum.js @@ -16,9 +16,18 @@ const { NotImplementedError } = require('../lib'); * * The result should be 9 */ -function getMatrixElementsSum(/* matrix */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function getMatrixElementsSum( matrix ) { + let sum = 0; + + for (let i = 0; i < matrix.length; i++) { + for (let j = 0; j < matrix[0].length; j++) { + if (i === 0 || matrix[i - 1][j] !== 0) { + sum += matrix[i][j]; + } + } + } + + return sum; } module.exports = { diff --git a/src/sum-digits.js b/src/sum-digits.js index ac605aff3d..df3d21c1b9 100644 --- a/src/sum-digits.js +++ b/src/sum-digits.js @@ -12,9 +12,19 @@ const { NotImplementedError } = require('../lib'); * For 91, the result should be 1 (9 + 1 = 10, 1 + 0 = 1) * */ -function getSumOfDigits(/* n */) { - // Remove line below and write your code here - throw new NotImplementedError('Not implemented'); +function getSumOfDigits( n ) { + let str = n.toString(); + let sum = 0; + + for (let i = 0; i < str.length; i++) { + sum += parseInt(str[i]); + } + + if (sum <= 9) { + return sum; + } + + return getSumOfDigits(sum); } module.exports = {