Skip to content

js katas #50

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

Open
wants to merge 5 commits into
base: master
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
107 changes: 93 additions & 14 deletions src/arrays.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,141 @@
//const array=["cat","dog","elephant","fox"];
const getNthElement = (index, array) => {
if (index>0 && index<=array.length-1){
return array[index];
}
if(index>array.length-1){
return array[index-4];
}
if(index===0){
return array[0];
}
};

// your code here
};


const arrayToCSVString = array => {
// your code here

let n =[array];
return n.toString();
};


const csvStringToArray = string => {
return string.split(",");
// your code here
};

//const array = [];
//const array2 = [1, 2, 3];
const addToArray = (element, array) => {
array.push(element);


// your code here
};

const array = ['a', 'b', 'c'];
const array2 = [1, 2, 3];
const addToArray2 = (element, array) => {
let newArray=array.concat(element);
return newArray;
// your code here
};

const removeNthElement = (index, array) => {
return array.splice(index,1);
// your code here
};

const numbersToStrings = numbers => {
const m=numbers.toString();
return m.split(',');
// your code here
};

const uppercaseWordsInArray = strings => {
const newString=strings.map((str) =>str.toUpperCase())
return newString;
// your code here
};

const reverseWordsInArray = strings => {
// your code here
};
return strings.map(string => string.split('').reverse().join(''));
}



const onlyEven = numbers => {
// your code here
};
let Array5=numbers.filter(number => number%2===0);
return Array5;

const removeNthElement2 = (index, array) => {
// your code here
};


const removeNthElement2 = (index,array) => {
return array.filter((element)=>{
if (element!==array[index]){
return element
}
})
}


const elementsStartingWithAVowel = strings => {
// your code here
};
return strings.filter((string)=>{
if(string.charAt(0)==="a"||string.charAt(0)==="e"||string.charAt(0)==="i"||string.charAt(0)==="o"||string.charAt(0)==="u"||string.charAt(0)==="A"||string.charAt(0)==="E"||string.charAt(0)==="I"||string.charAt(0)==="O"||string.charAt(0)==="U"){
return string
}
})

}







const removeSpaces = string => {
// your code here
const stringArray=string.split(" ");
const namesCombined=stringArray.reduce((acc,curr)=>{
return acc+curr
})
return namesCombined;
};

const sumNumbers = numbers => {
// your code here
const sumNumbers=numbers.reduce((acc,curr)=>{
return acc+curr;
})
return sumNumbers;
};

const sortByLastLetter = strings => {
// your code here
};
return strings.sort((a, b) =>
(a.charCodeAt(a.length - 1) - b.charCodeAt(b.length - 1))
)}



//const stringy= strings.map((string)=>{
//return string.split("").reverse().join("")
//})
//const newS=stringy.sort();
//return newS.split("").reverse().join("")




//








module.exports = {
getNthElement,
Expand Down
97 changes: 89 additions & 8 deletions src/booleans.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,141 @@
function negate(a) {
return !a;
// your code here
};

function both(a, b) {
if (a===true && b===true){
return true;
}else{
return false;
}
// your code here
};
}

function either(a, b) {
if (a===true || b===true){
return true
}else{
return false;
}
};
// your code here
};


function none(a, b) {
if (a===true || b===true){
return false
}else{
return true;
}
// your code here
};

function one(a, b) {
// your code here
};
if(a===true && b===true){
return false;
}else if (a===true || b===true){
return true;
}else{
return false;
}
};



function truthiness(a) {
return Boolean(a);
}


// your code here
};


function isEqual(a, b) {
if(a===b){
return true;
}else{
return false;
}
// your code here
};

function isGreaterThan(a, b) {
if(a>b){
return true;
}else{
return false;
}
// your code here
};

function isLessThanOrEqualTo(a, b) {
if (a<=b){
return true;
}else{
return false;
}
// your code here
};

function isOdd(a) {
// your code here
if(a%2!==0){
return true;
}else{
return false;
}

};

function isEven(a) {
if(a%2===0){
return true;
}else{
return false;
}

// your code here
};

function isSquare(a) {
if (Number.isInteger(Math.sqrt(a))){
return true;
}else{
return false;
}
// your code here
};

function startsWith(char, string) {
if(string.startsWith(char)){
return true;
}else {
return false;
}
// your code here
};

function containsVowels(string) {
// your code here
};

const vowels = ["a" ,"e" ,"i", "o","u","A","B","C","D","E"];
let result=false;
for(let i=0;i<string.length;i++)
if(vowels.includes(string[i])){
result=true;
}
return result;
}





function isLowerCase(string) {
if(string===string.toLowerCase()){
return true;
}else{
return false;
}
// your code here
};

Expand Down
11 changes: 11 additions & 0 deletions src/numbers.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
function add (a, b) {
return a+b;
// your code here
}

function subtract (a, b) {
return a-b;
// your code here
}

function multiply (a, b) {
return a*b;
// your code here
}

function divide (a, b) {
return a/b;
// your code here
}

function power (a, b) {
return a**b;
// your code here
}

function round (a) {
return Math.round(a);
// your code here
}

function roundUp (a) {
return Math.ceil(a);
// your code here
}

function roundDown (a) {
return Math.floor(a);
// your code here
}

function absolute (a) {
return Math.abs(a);
// your code here
}

function quotient (a, b) {
return Math.trunc(a/b);
// your code here
}

function remainder (a, b) {
return a%b;
// your code here
}

Expand Down
Loading