Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bb6186

Browse files
committed
Add a question
1 parent 92b08cc commit 2bb6186

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,3 +1861,33 @@ const convertToRoman = number => {
18611861
---
18621862

18631863
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1864+
1865+
## 54. Scramble
1866+
1867+
Write a function that accepts two strings and returns `true` if some or all of the characters in the first string can be rearranged to match the second string.
1868+
1869+
```js
1870+
const scramble = (str1, str2) => {
1871+
// Your solution
1872+
};
1873+
1874+
console.log(scramble('scriptjava', 'javascript')); // true
1875+
console.log(scramble('scriptingjava', 'javascript')); // true
1876+
console.log(scramble('scriptsjava', 'javascripts')); // true
1877+
console.log(scramble('jscripts', 'javascript')); // false
1878+
console.log(scramble('javscripts', 'javascript')); // false
1879+
```
1880+
1881+
<details><summary>Solution</summary>
1882+
1883+
```js
1884+
const scramble = (str1, str2) => {
1885+
return [...str2].every(letter => str2.split(letter).length <= str1.split(letter).length);
1886+
};
1887+
```
1888+
1889+
</details>
1890+
1891+
---
1892+
1893+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /