From 5d2d3625a122b7c31723aa05b16e761fd8c35849 Mon Sep 17 00:00:00 2001 From: ryanmoehs Date: Tue, 28 Feb 2023 01:06:36 +0700 Subject: [PATCH] Assignment 2 --- Assignment/Assignment-2/p1.js | 5 +++++ Assignment/Assignment-2/p2.js | 1 + Assignment/Assignment-2/p3.js | 2 ++ 3 files changed, 8 insertions(+) diff --git a/Assignment/Assignment-2/p1.js b/Assignment/Assignment-2/p1.js index 7df2c13..d962a4f 100644 --- a/Assignment/Assignment-2/p1.js +++ b/Assignment/Assignment-2/p1.js @@ -22,5 +22,10 @@ Output: Even function evenOrOdd(num) { // Your code here + if (num % 2 == 0){ + return "Even"; + } else { + return "Odd"; + } } module.exports = evenOrOdd; \ No newline at end of file diff --git a/Assignment/Assignment-2/p2.js b/Assignment/Assignment-2/p2.js index 0d4e442..215321b 100644 --- a/Assignment/Assignment-2/p2.js +++ b/Assignment/Assignment-2/p2.js @@ -19,5 +19,6 @@ Output: "tneduts a ma I" function reverseString(str) { // Your code here + return str.split("").reverse().join(""); } module.exports = reverseString; \ No newline at end of file diff --git a/Assignment/Assignment-2/p3.js b/Assignment/Assignment-2/p3.js index 79ed397..0db0c2f 100644 --- a/Assignment/Assignment-2/p3.js +++ b/Assignment/Assignment-2/p3.js @@ -19,5 +19,7 @@ Output: ["Short", "Longer", "Longest"] function sortByLength(arr) { // Your code here + let sorted = arr.sort((a,b) => a.length - b.length); + return sorted; } module.exports = sortByLength; \ No newline at end of file