diff --git a/01_helloWorld/helloWorld.js b/01_helloWorld/helloWorld.js index df27036..b542f3b 100644 --- a/01_helloWorld/helloWorld.js +++ b/01_helloWorld/helloWorld.js @@ -1,5 +1,5 @@ const helloWorld = function() { - return '' + return 'Hello, World!' }; module.exports = helloWorld; diff --git a/02_repeatString/repeatString.js b/02_repeatString/repeatString.js index 4359bbe..02bdac7 100644 --- a/02_repeatString/repeatString.js +++ b/02_repeatString/repeatString.js @@ -1,5 +1,13 @@ -const repeatString = function() { - +const repeatString = function(str,n) { + if(n<0) + return "ERROR" + let s=""; + while(n) + { + s+=str; + n--; + } + return s; }; // Do not edit below this line diff --git a/03_reverseString/reverseString.js b/03_reverseString/reverseString.js index f6790f0..e9bcf5e 100644 --- a/03_reverseString/reverseString.js +++ b/03_reverseString/reverseString.js @@ -1,5 +1,5 @@ -const reverseString = function() { - +const reverseString = function(str) { + return str.split("").reverse().join(""); }; // Do not edit below this line diff --git a/04_removeFromArray/removeFromArray.js b/04_removeFromArray/removeFromArray.js index 1bedeb0..4c7aba0 100644 --- a/04_removeFromArray/removeFromArray.js +++ b/04_removeFromArray/removeFromArray.js @@ -1,5 +1,13 @@ -const removeFromArray = function() { - +const removeFromArray = function(arr,...args) { + for(let arg of args) + { + let index=arr.indexOf(arg); + if(index>=0) + { + arr.splice(index,1); + } + } + return arr }; // Do not edit below this line diff --git a/05_sumAll/sumAll.js b/05_sumAll/sumAll.js index 00880c7..c88fd64 100644 --- a/05_sumAll/sumAll.js +++ b/05_sumAll/sumAll.js @@ -1,4 +1,25 @@ -const sumAll = function() { +const sumAll = function(s,e) { + if(typeof(s)==="number" && typeof(e)=="number" && s>=0 && e>=0) + { + let sum=0; + if(s<=e) + { + for(let i=s;i<=e;i++) + { + sum+=i; + } + } + else + { + for(let i=s;i>=e;i--) + { + sum+=i; + } + } + return sum; + } + else + return "ERROR" }; diff --git a/06_leapYears/leapYears.js b/06_leapYears/leapYears.js index 681eeef..490d5eb 100644 --- a/06_leapYears/leapYears.js +++ b/06_leapYears/leapYears.js @@ -1,5 +1,8 @@ -const leapYears = function() { - +const leapYears = function(x) { + if ((x%4==0 && x%100) || (x%4==0 && x%100==0 && x%40==0)) + return true; + else + return false; }; // Do not edit below this line diff --git a/07_tempConversion/tempConversion.js b/07_tempConversion/tempConversion.js index 14153e0..0c5e9ce 100644 --- a/07_tempConversion/tempConversion.js +++ b/07_tempConversion/tempConversion.js @@ -1,7 +1,11 @@ -const convertToCelsius = function() { +const convertToCelsius = function(x) { + let c=((x-32)*5)/9; + return Math.round(c*10)/10; }; -const convertToFahrenheit = function() { +const convertToFahrenheit = function(x) { + let f=((x*9)/5)+32; + return Math.round(f*10)/10; }; // Do not edit below this line diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js index c22e8d2..921d0c9 100644 --- a/08_calculator/calculator.js +++ b/08_calculator/calculator.js @@ -1,25 +1,41 @@ -const add = function() { - +const add = function(x,y) { + return x+y }; -const subtract = function() { - +const subtract = function(x,y) { + return x-y }; -const sum = function() { - +const sum = function(a) { + let s=parseInt(0); + for(let i=0;ix.title) }; // Do not edit below this line diff --git a/12_findTheOldest/findTheOldest.js b/12_findTheOldest/findTheOldest.js index 366856a..87706ea 100644 --- a/12_findTheOldest/findTheOldest.js +++ b/12_findTheOldest/findTheOldest.js @@ -1,5 +1,14 @@ -const findTheOldest = function() { - +const findTheOldest = function(obj) { + return obj.reduce((acc,curr)=>{ + let birthCurr=curr.yearOfBirth + let deathCurr=("yearOfDeath" in curr)?curr.yearOfDeath:(new Date().getFullYear()); + let diffCurr=(deathCurr-birthCurr) + let birthAcc=acc.yearOfBirth + let deathAcc=("yearOfDeath" in acc)?acc.yearOfDeath:(new Date().getFullYear()); + let diffAcc=(deathAcc-birthAcc) + acc=(diffCurr>diffAcc)?curr:acc; + return acc; + }) }; // Do not edit below this line