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

Assignment_completed #30

Open
wants to merge 2 commits 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

Large diffs are not rendered by default.

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

/**
Expand All @@ -27,7 +27,7 @@ function findElement(arr, value) {
* [] => []
*/
function doubleArray(arr) {
throw new Error("Not implemented");
return arr.concat(arr);
}

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

}

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

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

/**
Expand All @@ -89,7 +106,12 @@ 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() {
var flag = document.getElementById("flexSwitchCheckChecked").checked
if (flag) {
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() {
var bulb = document.getElementById("bulb");
bulb.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() {
var bulb = document.getElementById("bulb");
bulb.src = BULB_OFF_URL;
}
102 changes: 95 additions & 7 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)
{
let s = "FizzBuzz";
return s;
}
else if(num%3===0)
{
let s = "Fizz";
return s;
}
else if(num%5===0)
{
let s = "Buzz";
return s;
}
else return num;
}

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

/**
Expand All @@ -50,7 +70,14 @@ function getFactorial(n) {
* -1,1 => 0 ( = -1 + 0 + 1 )
*/
function getSumBetweenNumbers(n1, n2) {
throw new Error("Not implemented");
let x = Math.min(n1,n2);
let y = Math.max(n1,n2);
let sum=0;
for(let i=x;i<=y;++i)
sum+=i;

return sum;

}

/**
Expand All @@ -69,7 +96,8 @@ 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,56 @@ function reverseString(str) {
* '{[(<{[]}>)]}' = true
*/
function isBracketsBalanced(str) {
throw new Error("Not implemented");
// let stack = [];

// // Traversing the Expression
// for(let i = 0; i < expr.length; i++)
// {
// let x = expr[i];

// if (x == '(' || x == '[' || x == '{' || x=='<')
// {

// // Push the element in the stack
// stack.push(x);
// continue;
// }

// // If current character is not opening
// // bracket, then it must be closing.
// // So stack cannot be empty at this point.
// if (stack.length == 0)
// return false;

// let check;
// switch (x){
// case ')':
// check = stack.pop();
// if (check == '{' || check == '[' || check=='<')
// return false;
// break;

// case '}':
// check = stack.pop();
// if (check == '(' || check == '[' || check=='<')
// return false;
// break;

// case ']':
// check = stack.pop();
// if (check == '(' || check == '{' || check=='<')
// return false;
// break;

// case '>':
// check = stack.pop();
// if (check == '(' || check == '{' || check=='[')
// return false;
// break;
// }
// }

// return (stack.length == 0);
}

/**
Expand Down Expand Up @@ -169,7 +246,18 @@ function timespanToHumanString(startDate, endDate) {
* 365, 10 => '365'
*/
function toNaryString(num, n) {
throw new Error("Not implemented");
let s="";
while(num>=1)
{
let a = num%n;
let t = String(a);

s = s+t;
num = Math.floor(num/n);
}

return s.split('').reverse().join('');

}

module.exports = {
Expand Down
23 changes: 17 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,7 @@ function getRectangleArea(width, height) {
* -3, 3 => 0
*/
function getAverage(value1, value2) {
throw new Error("Not implemented");
return Math.floor(value1+value2)/2;
}

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

return b/a*(-1);
}

/**
Expand All @@ -58,7 +59,8 @@ function getLinearEquationRoot(a, b) {
* 0 => 0
*/
function getLastDigit(value) {
throw new Error("Not implemented");

return Math.abs(value%10);
}

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

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

module.exports = {
Expand Down
7 changes: 6 additions & 1 deletion src/strangerThings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ function sleep(ms) {
TODO:
This function should return a list of all the distinct characters in UPPERCASE that have been typed in the textbox with the id "message"
*/
function getCharacters() {}
function getCharacters() {
li = []
var text = document.getElementById("message").value.toUpperCase();
li.push(text);
return li;
}

/*
Sets the CSS properties of the DOM elements to create a nice visual effect
Expand Down
Loading