Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks Completed #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jest-html-reporters-attach/test/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions jest-html-reporters-attach/test/result.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 42 additions & 6 deletions src/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
* [0, 1, 2, 3, 4, 5], 5 => 5
*/
function findElement(arr, value) {
throw new Error("Not implemented");
for(let i=0;i<arr.length;i++)
{
if(arr[i]==value)
{
return i;
}
}
return -1;
}

/**
Expand All @@ -27,7 +34,16 @@ function findElement(arr, value) {
* [] => []
*/
function doubleArray(arr) {
throw new Error("Not implemented");
let arr1=[];
for(let i=0;i<arr.length;i++)
{
arr1.push(arr[i]);
}
for(let i=0;i<arr.length;i++)
{
arr1.push(arr[i]);
}
return arr1;
}

/**
Expand All @@ -42,7 +58,13 @@ function doubleArray(arr) {
* [] => []
*/
function getArrayOfPositives(arr) {
throw new Error("Not implemented");
for(let i=0;i<arr.length;i++){
if(arr[i]<=0){
arr.splice(i,1);
i--;
}
}
return arr;
}

/**
Expand All @@ -59,7 +81,13 @@ function getArrayOfPositives(arr) {
* [ false, 0, NaN, '', undefined ] => [ ]
*/
function removeFalsyValues(arr) {
throw new Error("Not implemented");
for(let i=0;i<arr.length;i++){
if(!arr[i]){
arr.splice(i,1);
i--;
}
}
return arr;
}

/**
Expand All @@ -73,7 +101,11 @@ function removeFalsyValues(arr) {
* [ 'angular', 'react', 'ember' ] => [ 7, 5, 5 ]
*/
function getStringsLength(arr) {
throw new Error("Not implemented");
let arr1=[];
for(let i=0;i<arr.length;i++){
arr1.push(arr[i].length);
}
return arr1;
}

/**
Expand All @@ -89,7 +121,11 @@ function getStringsLength(arr) {
* [ 1, 10, 100, 1000 ] => 1111
*/
function getItemsSum(arr) {
throw new Error("Not implemented");
let sum=0;
for(let i=0;i<arr.length;i++){
sum+=arr[i];
}
return sum;
}

module.exports = {
Expand Down
20 changes: 17 additions & 3 deletions src/bulb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@ const BULB_OFF_URL = "https://i.postimg.cc/KjK1wL3c/bulb-off.png";
TODO:
Fetch the status of the 'flexSwitchCheckChecked' checkbox and call the appropiate function to turn the bulb on or off
*/
function lightSwitch() {}
function lightSwitch() {
const checkbox = document.getElementById('flexSwitchCheckChecked');

if (checkbox.checked) {
bulb_on();
} else {
bulb_off();
}
}

/*
TODO:
Set the "bulb" element's Image src to be the image specified by BULB_ON_URL
*/
function bulb_on() {}
function bulb_on() {
const bulbElement = document.getElementById('bulb');
bulbElement.src = BULB_ON_URL;
}

/*
TODO:
Set the "bulb" element's Image src to be the image specified by BULB_OFF_URL
*/
function bulb_off() {}
function bulb_off() {
const bulbElement = document.getElementById('bulb');
bulbElement.src = BULB_OFF_URL;
}
93 changes: 84 additions & 9 deletions src/conditionalAndLoops.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@
*
*/
function getFizzBuzz(num) {
throw new Error("Not implemented");
if(num%3==0 && num%5==0)
{
return 'FizzBuzz';
}
else if(num%3==0)
{
return 'Fizz';
}
else if(num%5==0)
{
return 'Buzz';
}
else
{
return num;
}
}

/**
Expand All @@ -34,7 +49,12 @@ function getFizzBuzz(num) {
* 10 => 3628800
*/
function getFactorial(n) {
throw new Error("Not implemented");
let fact=1;
for(let i=1;i<=n;i++)
{
fact=fact*i;
}
return fact;
}

/**
Expand All @@ -50,7 +70,12 @@ function getFactorial(n) {
* -1,1 => 0 ( = -1 + 0 + 1 )
*/
function getSumBetweenNumbers(n1, n2) {
throw new Error("Not implemented");
let sum=0;
for(let i=n1;i<=n2;i++)
{
sum=sum+i;
}
return sum;
}

/**
Expand All @@ -69,7 +94,10 @@ function getSumBetweenNumbers(n1, n2) {
* 10,10,10 => true
*/
function isTriangle(a, b, c) {
throw new Error("Not implemented");
if(a+b>c && a+c>b && b+c>a)
return true;
else
return false;
}

/**
Expand All @@ -85,7 +113,7 @@ function isTriangle(a, b, c) {
* 'noon' => 'noon'
*/
function reverseString(str) {
throw new Error("Not implemented");
return str.split("").reverse().join("");
}

/**
Expand All @@ -110,7 +138,26 @@ function reverseString(str) {
* '{[(<{[]}>)]}' = true
*/
function isBracketsBalanced(str) {
throw new Error("Not implemented");
let flag = true;
let arr = [];
let open = ['[', '{', '(', '<'];
let close = [']', '}', ')', '>'];
for (let i = 0; i < str.length; i++) {
if (open.indexOf(str[i]) != -1) {
arr.push(str[i]);
}
else if (close.indexOf(str[i]) != -1) {
let openIndex = open.indexOf(arr.pop());
let closeIndex = close.indexOf(str[i]);
if (openIndex != closeIndex) {
flag = false;
}
}
}
if (arr.length != 0) {
flag = false;
}
return flag;
}

/**
Expand Down Expand Up @@ -145,8 +192,36 @@ function isBracketsBalanced(str) {
*
*/
function timespanToHumanString(startDate, endDate) {
throw new Error("Not implemented");
}
const diff = endDate - startDate;
const seconds = diff / 1000;
const minutes = seconds/60;
const hours = minutes / 60;
const days = hours / 24;

if (seconds <= 45) {
return 'a few seconds ago';
} else if (seconds <= 90) {
return 'a minute ago';
} else if (minutes <= 45) {
return `${Math.floor(minutes)} minutes ago`;
} else if (minutes <= 90) {
return 'an hour ago';
} else if (hours <= 22) {
return `${Math.floor(hours)} hours ago`;
} else if (hours <= 36) {
return 'a day ago';
} else if (days <= 25) {
return `${Math.ceil(days)} days ago`;
} else if (days <= 45) {
return 'a month ago';
} else if (days <= 345) {
return `${Math.ceil(days / 30)} months ago`;
} else if (days <= 545) {
return 'a year ago';
} else {
return `${Math.ceil(days / 365)} years ago`;
}
}

/**
* Returns the string with n-ary (binary, ternary, etc, where n<=10) representation of
Expand All @@ -169,7 +244,7 @@ function timespanToHumanString(startDate, endDate) {
* 365, 10 => '365'
*/
function toNaryString(num, n) {
throw new Error("Not implemented");
return num.toString(n);
}

module.exports = {
Expand Down
38 changes: 32 additions & 6 deletions src/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 5, 5 => 25
*/
function getRectangleArea(width, height) {
throw new Error("Not implemented");
return width*height;
}

/**
Expand All @@ -26,7 +26,13 @@ function getRectangleArea(width, height) {
* -3, 3 => 0
*/
function getAverage(value1, value2) {
throw new Error("Not implemented");
let average = (value1 + value2) / 2;

if (average === Infinity) {
return Number.MAX_VALUE;
}

return average;
}

/**
Expand All @@ -42,7 +48,12 @@ function getAverage(value1, value2) {
* 5*x = 0 => 0
*/
function getLinearEquationRoot(a, b) {
throw new Error("Not implemented");
let x = -b/a;
if (x === 0) {
return 0;
} else {
return x;
}
}

/**
Expand All @@ -58,7 +69,8 @@ function getLinearEquationRoot(a, b) {
* 0 => 0
*/
function getLastDigit(value) {
throw new Error("Not implemented");
let a = value%10;
return Math.abs(a);
}

/**
Expand All @@ -73,7 +85,8 @@ function getLastDigit(value) {
* '-525.5' => -525.5
*/
function parseNumberFromString(value) {
throw new Error("Not implemented");
let a = Number(value);
return a;
}

/**
Expand All @@ -94,7 +107,20 @@ function parseNumberFromString(value) {
* 17 => true
*/
function isPrime(n) {
throw new Error("Not implemented");
let a = true;
if(n==1){
return false;
}
if(n==2){
return true;
}
for(let i=2;i<n;i++){
if(n%i==0){
a = false;
break;
}
}
return a;
}

module.exports = {
Expand Down
Loading