加载中…

加载中...

My FreeCodeCamp Bonfire solutions

转载 2015-06-16 17:31:52

Bonfire: Find the Longest Word in a String

or:

Bonfire: Title Case a Sentence

Return the provided string with the first letter of each word capitalized.

Bonfire: Return Largest Numbers in Arrays

Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.

Bonfire: Confirm the Ending

Check if a string (first argument) ends with the given target string (second argument).

Bonfire: Repeat a string repeat a string

or:

Bonfire: Chunky Monkey

Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a multidimensional array.

or:

Bonfire: Mutations

Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

For example, ['hello', 'Hello'], should return true because all of the letters in the second string are present in the first, ignoring case.

The arguments ['hello', 'hey'] should return false because the string 'hello' does not contain a 'y'.

Lastly, ['Alien', 'line'], should return true because all of the letters in 'line' are present in 'Alien'.

Bonfire: Falsey Bouncer

Remove all falsey values from an array.

Falsey values in javascript are false, null, 0, "", undefined, and NaN.

Bonfire: Where art thou

Make a function that looks through a list (first argument) and returns an array of all objects that have equivalent property values (second argument).

​Bonfire: Seek and Destroy

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.

Bonfire: Where do I belong

Return the lowest index at which a value (second argument) should be inserted into a sorted array (first argument).

For example, where([1,2,3,4], 1.5) should return 1 because it is greater than 1 (0th index), but less than 2 (1st index).

Bonfire: Sum All Numbers in a Range

We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.

The lowest number will not always come first.

or:

Bonfire: Diff Two Arrays

Compare two arrays and return a new array with any items not found in both of the original arrays.

or:

Bonfire: Roman Numeral Converter

Convert the given number into a roman numeral.

All roman numerals answers should be provided in upper-case.

Bonfire: Search and Replace

Perform a search and replace on the sentence using the arguments provided and return the new sentence.

First argument is the sentence the perform the search and replace on.

Second argument is the word that you will be replacing (before).

Third argument is what you will be replacing the second argument with (after).

NOTE: Preserve the case of the original word when you are replacing it. For example if you mean to replace the word 'Book' with the word 'dog', it should be replaced as 'Dog'.

Bonfire: Pig Latin

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay".

If a word begins with a vowel you just add "way" to the end.

Bonfire: DNA Pairing

The DNA strand is missing the pairing element. Match each character with the missing element and return the results as a 2d array.

Base pairs

are a pair of AT and CG. Match the missing element to the provided character.

Return the provided character as the first element in each array.

Bonfire: Missing letters

Find the missing letter in the passed letter range and return it.

If all letters are present in the range, return undefined.

Bonfire: Sorted Union

Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.

In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.

The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.(use the Array.reduce() method)

Bonfire: Convert HTML Entities​

Convert the characters "&", "<", ">", '"', and "'", in a string to their corresponding HTML entities.

Bonfire: Spinal Tap Case

Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.

​spinalCase("thisIsSpinalTap")        //this-is-spinal-top

Bonfire: Sum All Odd Fibonacci Numbers​

Return the sum of all odd Fibonacci numbers up to and including the passed number if it is a Fibonacci number.

The first few numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8, and each subsequent number is the sum of the previous two numbers.

As an example, passing 4 to the function should return 5 because all the odd Fibonacci numbers under 4 are 1, 1, and 3.

Bonfire: Sum All Primes

Sum all the prime numbers up to and including the provided number.

A prime number is defined as having only two divisors, 1 and itself. For example, 2 is a prime number because it's only divisible by 1 and 2. 1 isn't a prime number, because it's only divisible by itself.

The provided number may not be a prime.

Bonfire: Smallest Common Multiple

Find the smallest number that is evenly divisible by all numbers in the provided range.

The range will be an array of two numbers that will not necessarily be in numerical order.

Bonfire: Steamroller

Flatten a nested array. You must account for varying levels of nesting.

Bonfire: Binary Agents

Return an English translated sentence of the passed binary string.

The binary string will be space separated.

Bonfire: Everything Be True

Check if the predicate (second argument) returns truthy (defined) for all elements of a collection (first argument).

For this, check to see if the property defined in the second argument is present on every element of the collection.

Remember, you can access object properties through either dot notation or [] notation.

Bonfire: Arguments Optional

Create a function that sums two arguments together. If only one argument is provided, return a function that expects one additional argument and will return the sum.

For example, add(2, 3) should return 5, and add(2) should return a function that is waiting for an argument so that var sum2And = add(2); return sum2And(3); // 5

If either argument isn't a valid number, return undefined.

Bonfire: Drop it

Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.



阅读(0) 评论(0) 收藏(0) 转载(0) 举报
分享

评论

重要提示:警惕虚假中奖信息
0条评论展开
相关阅读
加载中,请稍后
Noyio_
  • 博客等级:
  • 博客积分:0
  • 博客访问:4,307
  • 关注人气:0
  • 荣誉徽章:

相关博文

新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

新浪公司 版权所有