Table Of Contents
- Testing 1-2-3
- π Description
- π€ Thinking
- π¨βπ» Code
- Stop gninnipS My sdroW!
- π Description
- π€ Thinking
- π¨βπ» Code
- Credit Card Mask
- π Description
- π€ Thinking
- π€·ββοΈ What?
- π¨βπ» Code
Testing 1-2-3 : β by acr
π Description
Write a function which takes a list of strings and returns each line prepended by the correct number.
Examples:
number([]) // => []
number(["a", "b", "c"]) // => ["1: a", "2: b", "3: c"]
π€ Thinking
map
over the array and return an array using template literal every element with its index
π¨βπ» Code
const number = arr => arr.map((elm, i) => `${i+1}: ${elm}`)
Stop gninnipS My sdroW! : β by xDranik
π Description
Write a function that takes in a string of one or more words, and returns the same string, but with
all five or more letter words reversed
(Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
Examples:
spinWords( "Hey fellow warriors" ) // => "Hey wollef sroirraw"
spinWords( "This is a test") // =>"This is a test"
spinWords( "This is another test" ) // =>"This is rehtona test"
π€ Thinking
Turn the string into an array
of words (strings)
Then Check if the word length >= 5
If true
I will reverse
the word(s)
Then join
it all
π¨βπ» Code
const spinWords = str => {
const arr = str.split(" ");
const spinedarr = arr.map(word => {
return word.length >= 5 ? word.split("").reverse().join("") : word;
})
return spinedarr.join(" ");
}
Credit Card Mask : β by samranjbari
π Description
Write a function maskify, which changes all but the last four characters into '#'.
Examples:
maskify("4556364607935616") // => "############5616"
maskify( "64607935616") // => "#######5616"
maskify( "1") // => "1"
π€ Thinking
I'm will make an array
and then slice
it so I get the last 4 digits
Then use the padStart
method to create a string with the same length with that starts with #
s
π€·ββοΈ What?
MDN:
The
padStart()
method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.
π¨βπ» Code
const maskify = cc => {
const last4 = cc.split("").slice(-4);
const masked = cc.length >= 4 ? last4.join("").padStart(cc.length, "#") : cc;
return masked
}
Top comments (1)
You're doing great!!!
Just one note tho.
When creating a function or a method that takes in param/props the name should be more clear and specific for better readability. when you have time you should check The Art Of Readable Code. It will 1up your game for sure!