codingforeveryone / js Goto Github PK
View Code? Open in Web Editor NEWThis project forked from gitter-badger/js-1
Become familiar with GitHub by solving JavaScript issues
This project forked from gitter-badger/js-1
Become familiar with GitHub by solving JavaScript issues
@JMurphyWeb, @Bektaz I've done some reasearch on GitHub workflows inspired by our recent conversation and this comment.
I've found a good article on GitHub Flow.
So after reading that, I have a few ideas.
Please let me know if that makes sense and if anything can be improved?
Function nthChar takes 1 parameter - an array of n words.
You must concatenate the nth letter from each word to construct a new word which should returned as a string.
Note: Test cases contain valid input only - i.e. a string array or an empty array.
function nthChar(words){
...
}
so nthChar(['yxx','xex','xxs']) should return 'yes'
This is one of my katas on Codewars called Substring Fun if you want to practice:
Given an array of numbers, return the difference between the largest and smallest values.
For example:
[23, 3, 41, 21, 16]
should return 20
(i.e., 23 - 3).
[1, 434, 555, 34, 112]
should return 554
(i.e., 555 - 1).
The array will contain a minimum of two elements.
This is the link to Codewars.
Create a function that takes a number and finds the factors of it, listing them in descending order.
If the parameter is not an integer or is a negative integer, return -1
The returned factors should be in an array
Example:
factors(54)
should return [54, 27, 18, 9, 6, 3, 2, 1]
I have an idea which is designed to assign anyone new to this repository a problem that they can then practice using the guide set out by @patrickwalkowicz in the README.
Each new member of the repo will always find an easy problem waiting for them.
Once they have reserved and then solved the problem, they must create a new easy problem, designated for the next new member to the repo.
To distinguish the "New Member" problem, it should be named new-member-1, new-member-2 ...
This way there is always a simple JS problem to solve for any new member to this repository. Let me know your thoughts.
As we're a little light on problems at the moment, here's another from my vault:
For a given two numbers your mission is to derive a function that evaluates whether two given numbers are abundant, deficient or perfect and whether together they are amicable.
An abundant number or excessive number is a number for which the sum of its proper divisors is greater than the number itself.
The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16 (> 12).
A deficient number is a number for which the sum of its proper divisors is less than the number itself (and for this case equal to).
The first few deficient numbers are: 1, 2, 3, 4, 5, 7, 8, 9.
A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself.
The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6.
Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper divisors of 6 are 1, 2, and 3.)
For example, the smallest pair of amicable numbers is (220, 284); for the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110, of which the sum is 284; and the proper divisors of 284 are 1, 2, 4, 71 and 142, of which the sum is 220.
For a given two numbers, derive function deficientlyAbundantAmicableNumbers(num1, num2) which returns a string with first and second word either abundant or deficient depending on whether num1 or num2 are abundant, deficient or perfect. The string should finish with either amicable or not amicable depending on the relationship between num1 and num2.
e.g. deficientlyAbundantAmicableNumbers(220, 284) returns "abundant deficient amicable" as 220 is an abundant number, 284 is a deficient number and amicable because 220 and 284 are an amicable number pair.
On codewars -> Deficiently Abundant Perfect Amicable Numbers
Greatest Difference
You will be given an array of arrays. Each nested array will contain a set of increasing positive integers. Your function should return the value of the greatest difference between any two sequential numbers within the same array.
For example...
var sampleArr1 = [
[4, 7, 8, 15, 22, 33, 35, 41, 53],
[23, 44, 67, 68, 99, 102],
[199, 203, 205, 213, 218],
[10, 12, 77, 133, 150]
];
var sampleArr2 = [
[361, 403, 425, 480, 576, 672, 730, 733, 805, 826],
[896, 982],
[303, 399, 489, 490, 499, 515, 578],
[553, 555, 646, 692, 697],
[272, 338, 353, 432, 529, 553, 565]
];
greatestDiff(sampleArr1); // Returns 65
greatestDiff(sampleArr2; // Returns 97
A spoonerism is a spoken phrase in which the first letters of two of the words are swapped around, often with amusing results.
This issue is taken from my very first Codewars Kata
In its most basic form a spoonerism is a two word phrase in which only the first letters of each word are swapped:
"not picking" --> "pot nicking"
Your task is to create a function that takes a string of only two words, separated by a space and returns a spoonerism of those words in a string, as in the above example.
NOTE: Spoonerisms can be more complex. For example, three-word phrases in which the first letters of the first and last words are swapped: "pack of lies" --> "lack of pies"
or more than one letter from a word is swapped: "flat battery --> "bat flattery"
You are NOT expected to account for these, or any other linguistic nuances involved in spoonerisms.
These are suggestions for improvements and clarifications to CONTRIBUTING.md.
Suggestion by @tas12 - For step 1: I think when a new member needs to open an issue to request a problem you could include that bit about what they should name the issue (before it was "New member in need of a problem"). Then it's easier to identify issues that are new problem requests.
Suggestion by @andrewMacmurray - Maybe add something here like "Join our chat room on gitter, we'd love to hear from you!", just to make it very clear this is a friendly and sociable repo. This could also go at the top of the README.md by the gitter channel button!
Suggestion by @tu6619 - What about adding something to the line "Keep the problem simple!"? Maybe something like "Have a look at 8kyu and 7kyu Katas on Codewars for inspiration!".
You are a first-time online publisher and would like to post your articles online. You want to build an archive which can store and update article information and enables "likes" from social networks.
The "archive" array will store an object for each article. Each object shall contain the following article info:
Please use the provided names for each info-field.
You should write the following functions:
new article("Something, Something!");
//would return:
{
articleId: 1,
title:"Something, Something!",
filename: "Something_Something.txt",
likes: {facebook:0,twitter:0,googlePlus:0}
}
like("Something, Something!","twitter");
//would return:
{facebook:0,twitter:1,googlePlus:0}
remove("Something!, Something!");
//would return:
[{
articleId: 1,
title:"Fancy new article",
filename: "Fancy_new_article.txt",
likes: {facebook:0,twitter:0,googlePlus:0}
}]
Thanks for today's hangout! For those who couldn't make it, we've decided to collaborate on manageable projects to practice with. The first one we chose is building a front of a checklist application. So this would require HTML + CSS + JavaScript/jQuery.
What I think the application should be able to do:
@MyPitit, @FrancescoPalma, @daymos, @thevalent, @Bektaz, @JMurphyWeb, what do you think?
Problem: find if an element x is present in a vector using binary search principle. The function must be written using recursion.
I think this is a classic problem, so if you look around you will find the solution already made. So I try to give here the basic explanation to solve it without having to look around too much. Probably you know already this topic, but I麓ll write a couple of lines anyway.
Binary search is efficient, because it never uses more the log_2(N) attempt to find an element in a vector of N elements.
You need the data to be ordered. You cannot assume the data will be ordered. You can assume it will be an array of integers.
The principle is that you divide the data in 2 parts, and check if the number you are searching for, is bigger or smaller then the value you have on the division. If not you repeat with one of the 2 subset of data and go on until you find the value.
Write a function groupIn10s which takes any number of arguments, and groups them into sets of 10s and sorts each group in ascending order.
The return value should be an array of arrays, so that numbers between 0-9 inclusive are in position 0 and numbers 10-19 are in position 1, etc.
Here's an example of the required output:
const grouped = groupIn10s(8, 12, 38, 3, 17, 19, 25, 35, 50)
grouped[0] // [3, 8]
grouped[1] // [12, 17, 19]
grouped[2] // [25]
grouped[3] // [35, 38]
grouped[4] // undefined
grouped[5] // [50]
The kata is also on CodeWars
Monoalphabetic substitution cipher
Write a function subCipher
that takes a string and replaces each letter with the next letter in the alphabet. Letters in the encoded string should be in uppercase.
Example:
subCipher("welcome to the group!"); //returns "XFMDPNF UP UIF HSPVQ!"
Repl.it is a good place to try out your code.
If not, which new-member-# can I be?
Write a function that takes a size and returns a string of alternating '1s' and '0s'.
the string should start with a 1.
a string with size 6 should return : '101010'
with size 4 should return : '1010'
with size 12 should return : '101010101010'
The size will take positive whole numbers.
There is a tube strike today so instead of getting the London Underground home you have decided to take the bus. It's a hot day and you have been sitting on the bus for over an hour, but the bus is hardly moving. Your arm is sticking to the window and sweat drips off your nose as you try to read your neighbour's book when you say to yourself, "This is ridiculous. I could have walked faster than this!" Suddenly you have an idea for an app that helps people decide whether to walk or take the bus home when the London Underground is on strike.
You rush home (relatively speaking) and begin to define the function that will underpin your app.
You must create a function which takes three parameters; walking distance home, distance the bus must travel, and the combined distance of walking from the office to the bus stop and from the bus stop to your house. All distances are in kilometres.
So for example, if your home is 5km away by foot, and the bus that takes you home travels 6km, but you have to walk 500 metres to the bus stop to catch it and 500 metres to your house once the bus arrives (i.e. 1km in total), which is faster, walking or taking the bus?
Walking speed and bus driving speed have been given to you as two pre-loaded constants.
walk
= 5 (km/hr)
bus
= 8 (km/hr)
The function must return the fastest option, either "Walk" or "Bus". If the walk is going to be over 2 hours, the function should recommend that you take the bus. If the walk is going to be under 10 minutes, the function should recommend that you walk.
http://www.codewars.com/kata/tube-strike-options-calculator/javascript
I've got a string manipulation problem to solve for you.
Write a function that will revert a word but preserve the original lowercase/uppercase letter order. It's easiest to explain with examples:
My idea is to start with simple one-word input and improve as we go - eventually getting to multiple words and characters other than alphabetical.
Slightly adapted the first problem from project euler:
https://projecteuler.net/problem=1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Create a function that will find the sum of all the multiples of 3 or 5 below an integer x
function sumOfMultiples(x){
//
}
multiFilter
which receives two arrays as parameters. The first one is the collection to be filtered and the second one is an array of functions
. The function should return all elements which pass all filter functions.That is, if we have two functions:
function isEven(el){
return el % 2 === 0;
}
and
function isGTten(el){
return el > 10;
}
then
multiFilter([1,2,3,4,10,11,12,20,21,22], [isEven, isGTten]) // returns [12,20,22]
multiFilter
which receives one array of filter functions
. The function should return a function that receives one element (a compound filter function).That is, if we have two functions:
function isEven(el){
return el % 2 === 0;
}
and
function isGTten(el){
return el > 10;
}
then
[1,2,3,4,10,11,12,20,21,22].filter(multiFilter([isEven, isGTten])) // returns [12,20,22]
Create a function strCount (takes an object as argument) that will count all string values inside an object. For example:
strCount({
first: "1",
second: "2",
third: false,
fourth: ["anytime",2,3,4],
fifth: null
})
//returns 3
New-Member-13-The Christmas List
Santa has just finished the Christmas delivery but it's the time he dreads, when he starts getting letters from upset children stating they have been given the wrong presents.
We all know Santa checks his list twice but he also checks a third time after delivery
Help Santa to make sure that all the presents were delivered correctly by writing a function that takes two objects and compares whether they are the same
christmasMasterList2015 = {
Johnny: "coal",
Petey: "Monster Truck",
Tommy: "Iphone 6 plus with unlimited 4g contract"
}
presentsDelivered2015 = {
Johnny: "coal",
Petey: "Monster Truck",
Tommy: "Iphone 6 plus with unlimited 4g contract"
}
presentsDelivered2014 = {
Johnny: "coal",
Petey: "Tricycle",
Tommy: "Marvel Unlimited Subscription"
}
Example
allPresentsDelvieredCorrectly(christmasMasterList2015, presentsDelivered2015)
//returns true
allPresentsDelvieredCorrectly(christmasMasterList2015, presentsDelivered2014)
//returns false
You and your best friend Stripes have just landed your first high school jobs! You'll be delivering newspapers to your neighbourhood on weekends. For your services you'll be charging a set price depending on the quantity of the newspaper bundles.
The cost of deliveries is:
Stripes is taking care of the footwork doing door-to-door drops and your job is to take care of the finances. What you'll be doing is providing the cheapest possible quotes for your services.
Write a function that's passed an integer representing the amount of newspapers and returns the cheapest price. The returned number must be rounded to two decimal places.
Hi @Bektaz,
You created this js
repo in the codingforeveryone organisation rather than on your personal account which we take to mean that this is a resource for the whole community to benefit from 馃帀 馃憦
Could you please add both a description and a readme to the repo so that everyone may understand what the repo is about and how it should be used?
Thank you again for taking part in the codingforeveryone community !
Write a function that returns a perfect suare number and the square root of that number. See details in checkRoot/README.md
I did not come up with this problem, but it was one of the first ones I solved on CodeWars.
Given an array of numbers, find the largest pair sum in the array.
For example
[10,14,2,23,19] should return 42 (i.e. sum of 23,19)
[99,2,2,23,19] should return 122 (i.e. sum of 99,23)
Here you can find the original: http://www.codewars.com/kata/556196a6091a7e7f58000018
Hey all,
I'm in need of an issue to take on here.
Thanks
I suggest improving upon the provious version of revertString function. For reference, you can find specification of the original here.
String of any length, only alphabetical characters and spaces
String of reverted input, preserving the original order of capital letters and order of words.
Example:
Input: "Hello WorLD"
Output: "Olleh DlrOW"
Please modify the existing code so that it handles input like specified above and submit a pull request when ready.
Write a function that removes all the even characters from a string and returns them in an array. If the string is smaller than two characters and longer than 100 characters, the function should return "invalid string".
For example:
function evenChars("abcdefghijklm") {}
// should return ["b", "d", "f", "h", "j", "l"]
function evenChars("a")
// should return "invalid string"
I've posted this problem as a Codewars Kata if you want to practice!
There is a javascript file getNumberLength.js. The functionality of code needs to be checked with different kinds of inputs. For example the function gives wrong result when input is very large number with 30 zeroes.
One of my favorites on Codewars!
You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ['n', 's', 'w', 'e']).
You know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.
Note: you will always receive a valid array containing a random assortment of direction letters ('n', 's', 'e', or 'w' only). It will never give you an empty array (that's not a walk, that's standing still!).
A number is self-descriptive when the n'th digit describes the amount n appears in the number.
E.g. 21200:
There are two 0's in the number, so the first digit is 2.
There is one 1 in the number, so the second digit is 1.
There are two 2's in the number, so the third digit is 2.
There are no 3's in the number, so the fourth digit is 0.
There are no 4's in the number, so the fifth digit is 0
Numbers can be of any length up to 9 digits and are only full integers. For a given number derive a function selfDescriptive(num) that returns; true if the number is self-descriptive or false if the number is not.
Write a function that takes as its parameters some numbers representing the diameters of circles.
It should return the sum of the areas of all these circles, rounded to the nearest integer, as a string: "We have this much circle: xyz".
You don't know how many circles there will be, but you can assume there will be at least one.
function sumCircles(){
// codecodecode
}
sumCircles(2) // returns "We have this much circle: 3"
sumCircles(2, 3, 4)// returns "We have this much circle: 23"
The readme for the repo could do with some more explanation for total beginners with GitHub. No extensive guide but maybe a basic Do's and Dont's?
Also your Gitter message containing useful GitHub links will be useful to all newcomers:
Here's a good read on Git: https://github.com/NataliaLKB/learn-git-basics
And nice tutorial on resolving conflicts when merging http://www.gitguys.com/topics/merging-with-a-conflict-conflicts-and-resolutions/ (something you'll have to do when trying to synchronise thevalent/js to be up to date with codingforeveryone/js).
Create a function that returns the sum of 2 vectors BUT the returned vector must be within the bounds of a 10*10 area. Results outside the bounds should "wrap around" to stay inside. For example:
translate2D([5,7],[2,-1]) //should return [7,6]
translate2D([8,9],[3,5]) //should return [1,4]
Write a function to work out who is owed what when a group of friends all pay different amounts toward a bill.
Further points:
Example
3 friends go out together: A pays 拢20, B pays 拢15, and C pays 拢10 toward the bill. The function should return an object showing that A should receive 拢5, B should receive 拢0, and C should pay 拢5.
var group = {
A: 20,
B: 15,
C: 10
}
splitTheBill(group) // returns {A: 5, B: 0, C: -5}
We have a broken message machine that introduces noise to our incoming messages. We know that our messages are written using a-zA-Z
and white characters (like spaces or tabs). Unfortunately our machine introduces noise, which means that our message arrives with characters like: %$&/#路@|潞\陋
within our original message.
Your mission is to write a function which removes this noise from the message, but there is bad news, the computer designated to host our program has some limitations and we can't use loops in our scripts (that is, we can't use for
, while
and forEach
loops), instead, we should use regular expressions, map
, reduce
or/and replace
.
Example:
removeNoise("h%e&路%$路llo w&%or&$l路$%d")
// returns hello world
removeNoise("he%$路ll@o c$&%odi%&ng for ev|#路ery&$$#$on%$路e")
// returns hello conding for everyone
Given an array containing random occurrences of zeros and ones, write a function countOnes(arr) that returns the counts of the sequential ones in the array.
For example:
countOnes([0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1]) // returns [2, 4, 2]
Hi guys!
A new issue would be greatly appreciated, as I am new to the group.
Cheers!
You have an array of numbers 1 through 10 (JS: 1 through 10 or less). The array needs to be formatted correctly for the person reading the countdown of a spaceship launch.
Unfortunately, the person reading the countdown only knows how to read strings. After the array is sorted correctly make sure it's in a format he can understand.
Between each number should be a space and after the final number (1) should be the word 'liftoff!'
Example:
[8,1,10,2,7,9,6,3,4,5]
Should return
"10 9 8 7 6 5 4 3 2 1 liftoff!"
[1,2,4,3,5]
Should return
"5 4 3 2 1 liftoff!"
**Note I am not the original author of this exercise http://www.codewars.com/users/SpencerCDixon
create a function findSum() which can be used in the following way:
var plus2 = findSum(2);
plus2(5); => 7
OR
findSum(4)(6); => 10
Hi Everyone, have created a new branch with a problem I'm stuck on on codewars - it's this one if you want to have a look http://www.codewars.com/kata/52d3b68215be7c2d5300022f
Has anyone completed it yet? It's a nice OOP one about constructing an object that handles an events but can't get my head around what I'm doing wrong!
Create a new object called Stats
that has three methods:
median
should return the number at the midpoint in a sorted array. lowerQuartile
should return the number one quarter of the way through the array. upperQuartile
should return the number three quarters of the way through the array. When a cut-off point is between two numbers, take the average of the numbers on either side. Round your answer to a maximum of two decimal places.
All inputs will be valid arrays of numbers.
Here is the kata on codewars http://www.codewars.com/kata/quartile-methods
Given a string as input, move all of its vowel to the end of the string.
Example input: day
Example output: dya
Example input: apple
Example output: pplae
Note: All input string are of small capital letters, and the order of the vowels at the end should be the same as they were before.
Here's the link to the kata on codewars: http://www.codewars.com/kata/56bf3287b5106eb10f000899
Write a function in getNumberLength.js file which helps to correctly define the length of given number. Further details in getNumberLength/README.md file.
Write a function that checks whether all elements in an array are square numbers. The function should be able to take any number of array elements.
Your function should return true if all elements in the array are square numbers and false if not.
An empty array should return undefined.
Examples:
isSquare([1, 4, 9, 16]);
//returns true
isSquare([3, 4, 7, 9]);
//returns false
isSquare([]);
//returns undefined
@thevalent , @JMurphyWeb as I've mentioned in Gitter chat, I've decided to merge the pull request that was sent earlier. Thanks again for working on this one, guys!
I came up with another Git/JS exercise that presented itself along the way. The current revertString is working but I think it could use some tweaking style-wise (like fixing indentation so it's obvious which blocks belong to what functions, fixing spacing around operators, cutting down some line breaks etc). Please treat is as an exercise in fixing code (rather than writing functions from scratch). If you're interested, feel free to contribute.
See you around!
Given a string, write a function that returns the sum of all the digits in the string.
e.g. sumDigits("33 little frogs eat 44 squirrels every 2 days, ew") -> 16
A declarative, efficient, and flexible JavaScript library for building user interfaces.
馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google 鉂わ笍 Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.