This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This problem was asked by Google. | |
// Given a string of words delimited by spaces, reverse the words in string. For example, given "hello world here", return "here world hello" | |
// Follow-up: given a mutable string representation, can you perform this operation in-place? | |
const reverseWords = (str) => str.split(' ').reverse().join(' ') | |
console.log(reverseWords("hello world here") === "here world hello") // true | |
console.log(reverseWords("hello world here") === "hello world here") // false | |
console.log(reverseWords("who the hell are you") === "you are hell the who") // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createGreeter(greeting) { | |
return function (name) { | |
console.log(greeting + ", " + name); | |
}; | |
} | |
const sayHello = createGreeter("Hello"); | |
sayHello("Joe"); // Hello, Joe | |
sayHello("Mihail"); // Hello, Mihail | |
sayHello("Chris"); // Hello, Chris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* const levels = [ | |
[1001, 1], | |
[1000.5, 1], | |
[1000, 1], | |
[999, 1], | |
[988.5, 1], | |
[988, 1] | |
] */ | |
const levels = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const levels = [ | |
[1001, 1],[1000.5, 1],[1000, 1] | |
] | |
/** | |
* Returns the number rounded to the nearest interval. | |
* Example: | |
* | |
* roundToNearest(80, 100); // 100 | |
* roundToNearest(25, 15); // 30 |