-
Notifications
You must be signed in to change notification settings - Fork 14
/
03.String.js
65 lines (42 loc) · 1.78 KB
/
03.String.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* * * * * * * * * * * * * * * * * * * * * *
* PALEO JS PT 3: STRING METHODS *
* * * * * * * * * * * * * * * * * * * * * */
// Primitive values get methods too! Like the Array methods, these
// are called on the string itself, for example: `"abc".slice(1, 2)`.
// For your paleo versions, the string will be the first argument.
/** OBJECT.KEYS **/
// But first a little warmup before the actual String methods!
// This function takes an object and returns an array of it's keys.
// Example Usage:
// var obj = {a: 1, b: 2, c: 3};
// Object.keys(obj); --> returns ['a', 'b', 'c']
var keys = function(object) {
};
/** SLICE **/
// This useful method works on strings and arrays. It copies a sub-section
// based on a start index (inclusive) and an end index (non-inclusive).
// Note that there are a lot of creative ways `slice` handles its parameters!
// Both are optional, and you can even use negative indexes. Check out MDN
// (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
// if you are unfamiliar with how it should work.
// Example Usage:
// var str = "hello world";
// str.slice(0, 5); --> returns "hello"
// [1, 2, 3].slice(1); --> returns [2, 3]
var slice = function(stringOrArray, start, end) {
};
/** TRIM **/
// A handy little method for processing text. Returns the input string
// with all white space removed from the beginning and the end.
// Example Usage:
// var str = "\n hi there ";
// str.trim(); --> returns "hi there"
var trim = function(string) {
};
/** REPLACE **/
// Searches for a target sub-string and replaces it.
// Note that only the first instance is replaced.
// Example Usage:
// "axc".replace("x", "b"); --> returns "abc"
var replace = function(string, target, replacement) {
};